import Vue from 'vue'
import Vuet from 'vuet'
import VuetScroll from 'vuet-scroll'
import VuetRoute from 'vuet-route'
import VuetStore from 'vuet-store'
import httputil from '../httputil'
import utils from '../utils'
import context from '../main.js'//引用文件

Vue.use(Vuet)
  .use(VuetScroll)

Vuet
  .rule('route', VuetRoute)
  .rule('store', VuetStore)


export default new Vuet({
  pathJoin: '-',
  modules: {
    footer: {
      data() {
        return {
          home_foot_menu: [{
            id: 1,
            link: "/",
            default_icon: "/static/discovery.png",
            active_icon: "/static/discovery_selected.png",
            name: "首页"
          }, {
            id: 2,
            link: "/relationlink",
            default_icon: "/static/sale.png",
            active_icon: "/static/sale_selected.png",
            name: "关注"
          }, {
            id: 3,
            link: "/shop",
            default_icon: "/static/shop.png",
            active_icon: "/static/shop_selected.png",
            name: "商城"
          }, {
            id: 4,
            link: "/profile",
            default_icon: "/static/profile.png",
            active_icon: "/static/profile_selected.png",
            name: "我的"
          },]
        }
      },
      route: {
        once: true // 当前页面，只加载一次，这样我们就可以做上拉加载了
      },
      async fetch() {

      }
    },
    discovery: {
      data() {
        return {
          needFetch: true,
          bannerlist: [],
          authorities: {},
          deeppit: {},
          grasses: {},
          resoues: [],
          start: "",
          has_next: true,
          list: []
        }
      },
      // route: {
      //   once: true // 当前页面，只加载一次，这样我们就可以做上拉加载了
      // },
      skipToArticle(id) {
        this.needFetch = false
        this.app.$router.push({name: 'contentdetail', query: {id: id}})
        // setTimeout(() => {
        //   this.app.$router.push({ name: 'contentdetail', query: {id:id}})
        // }, 1)
      },
      skipToArticleChannel(id) {
        this.needFetch = false
        this.app.$router.push({name: 'articlechannel', query: {id: id}})
        // setTimeout(() => {
        //   this.app.$router.push({ name: 'articlechannel', query: {id:id}})
        // }, 1)
      },
      skipToArticleZcChannel(id) {
        this.needFetch = false
        this.app.$router.push({name: 'articlezcchannel', query: {id: id}})
      },
      skipToResouList() {
        this.needFetch = false
        this.app.$router.push({name: 'resoulist'})
      },

      getBannerList(type, done) {
        var that = this;
        httputil.request("banners", {}, function (successresult) {
          if (type == "down") {
            done();
          }
          that.bannerlist = successresult.banners
        }, function (errorresult) {
          if (type == "down") {
            done();
          }
        }, "GET", false, "")
      },
      getAuthoritiesList(type, done) {
        var that = this;
        httputil.request("authorities", {size: 3}, function (successresult) {
          if (type == "down") {
            done();
          }
          that.authorities = successresult
          console.log("yyyyyy")
        }, function (errorresult) {
          if (type == "down") {
            done();
          }
        }, "GET", false, "")
      },
      getDeeppitList(type, done) {
        var that = this;
        httputil.request("deeppit", {size: 3}, function (successresult) {
          if (type == "down") {
            done();
          }
          that.deeppit = successresult
        }, function (errorresult) {
          if (type == "down") {
            done();
          }
        }, "GET", false, "")
      },
      getGrassesList(type, done) {
        var that = this;
        httputil.request("grasses", {size: 5}, function (successresult) {
          if (type == "down") {
            done();
          }
          that.grasses = successresult
        }, function (errorresult) {
          if (type == "down") {
            done();
          }
        }, "GET", false, "")
      },
      getResouList(type, done) {
        var that = this;
        httputil.request("hot/search", {size: 9}, function (successresult) {
          if (type == "down") {
            done();
          }
          that.resoues = successresult.searches
        }, function (errorresult) {
          if (type == "down") {
            done();
          }
        }, "GET", false, "")
      },
      fetchSaleList(type, isShowLoading, requestStart, done) {
        var that = this
        var params = {};
        params.start = requestStart
        httputil.request("discounts", params, function (successresult) {
          that.showview = true
          that.has_next = successresult.discount_list.has_next == 0 ? false : true;
          if (type == "down" || type == "up") {
            done();
          }
          if (requestStart == "") {
            that.list = successresult.discount_list.discounts;
          } else {
            that.list = that.list.concat(successresult.discount_list.discounts);
          }
          if (successresult.discount_list.discounts.length != 0) {
            that.start = that.list[that.list.length - 1].id
            that.current_length = successresult.discount_list.discounts.length
          } else {

          }

        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      async fetch() {
        console.log("fetch")
        // this.onInit()
        if (this.needFetch) {
          this.onInit()
          this.vuet.store.discovery.$scroll.content.y = 0
        }
      },
      onRefresh(done) {
        this.getBannerList("down", done)
        this.getAuthoritiesList("down", done)
        this.getDeeppitList("down", done)
        this.getGrassesList("down", done)
        this.getResouList("down", done)
        this.start = ""
        this.fetchSaleList("down", false, this.start, done)
      },
      onGetmore(done) {
        // alert(this.has_next)
        if (this.has_next) {
          this.fetchSaleList("up", false, this.start, done)
        }
      },
      onInit() {
        this.getBannerList("init")
        this.getAuthoritiesList("init")
        this.getDeeppitList("init")
        this.getGrassesList("init")
        this.getResouList("init")
        this.start = ""
        this.fetchSaleList("init", false, this.start)
      },
    },
    home: {
      data() {
        return {
          needFetch: true,
          start: "",
          has_next: true,
          list: []
        }
      },
      fetchSaleList(type, isShowLoading, requestStart, done) {
        var that = this
        var params = {};
        params.start = requestStart
        httputil.request("note/latest", params, function (successresult) {
          that.showview = true
          that.has_next = successresult.note_list.has_next == 0 ? false : true;
          if (type == "down" || type == "up") {
            done();
          }
          if (requestStart == "") {
            that.list = successresult.note_list.notes;
          } else {
            that.list = that.list.concat(successresult.note_list.notes);
          }
          if (successresult.note_list.notes.length != 0) {
            that.start = that.list[that.list.length - 1].id
          } else {

          }

        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      async fetch() {
        if (this.needFetch) {
          this.onInit()
          this.vuet.store.home.$scroll.content.y = 0
        }
      },
      onRefresh(done) {
        this.start = ""
        this.fetchSaleList("down", false, this.start, done)
      },
      onGetmore(done) {
        // alert(this.has_next)
        if (this.has_next) {
          this.fetchSaleList("up", false, this.start, done)
        }
      },
      onInit() {
        this.start = ""
        this.fetchSaleList("init", false, this.start)
      },
    },
    relationlink: {
      data() {
        return {
          needFetch: true,
          start: "",
          has_next: true,
          list: [],
          isShowFeeds:true,
          userlist:[]
        }
      },
      follow(item) {
        var that = this
        var params = {id: item.id}
        httputil.request("fans/followed", params, function (successresult) {
          item.followed = successresult.followed
        }, function (errorresult) {

        }, "POST", false, "relationlink")
      },
      skipToUserpage(id) {
        this.needFetch = false
        this.app.$router.push({name: 'userpage', query: {id: id}})
      },
      likeArticle(item) {
        var that = this
        if (this.app.$getLoginStatus()) {
          if (item.feed_data.article.liked == 0) {
            item.feed_data.article.liked = 1
            item.feed_data.article.likes_total = item.feed_data.article.likes_total + 1
          } else {
            item.feed_data.article.liked = 0
            item.feed_data.article.likes_total = item.feed_data.article.likes_total - 1
          }
        }
        var params = {id: item.feed_data.article.id}
        httputil.request("like/article", params, function (successresult) {
          item.feed_data.article.liked = successresult.liked
        }, function (errorresult) {

        }, "POST", false, "relationlink")
      },
      skipToArticle(id) {
        this.needFetch = false
        this.app.$router.push({name: 'contentdetail', query: {id: id}})
      },
      sendClickBuy(item){
        var that = this
        httputil.request("discount/click", {discount_id:item.id}, function (successresult) {
          that.needFetch = false
          debugger
          if (window.location.href.indexOf(that.app.GLOBAL.skitToThirdWebSign) == -1) {
            window.location.replace(window.location.href + that.app.GLOBAL.skitToThirdWebSign)
          }
          window.location.href = item.link;
        }, function (errorresult) {
          that.needFetch = false
          if (window.location.href.indexOf(that.app.GLOBAL.skitToThirdWebSign) == -1) {
            window.location.replace(window.location.href + that.app.GLOBAL.skitToThirdWebSign)
          }
          window.location.href = item.link;
        }, "POST", true,"")
      },
      skipToDiscount(id) {
        this.needFetch = false
        this.app.$router.push({name: 'saledetail', query: {id: id}})
      },
      likeNote(item) {
        var that = this
        if (this.app.$getLoginStatus()) {
          if (item.feed_data.note.liked == 0) {
            item.feed_data.note.liked = 1
            item.feed_data.note.liked_total = item.feed_data.note.liked_total + 1
          } else {
            item.feed_data.note.liked = 0
            item.feed_data.note.liked_total = item.feed_data.note.liked_total - 1
          }
        }
        var params = {id: item.feed_data.note.id}
        httputil.request("like/note", params, function (successresult) {
          item.feed_data.note.liked = successresult.liked
        }, function (errorresult) {

        }, "POST", false, "relationlink")
      },
      skipToNote(id) {
        this.needFetch = false
        this.app.$router.push({name: 'notedetail', query: {id: id}})
      },
      geCommendUserList(isShowLoading){
        var that = this
        var params = {}
        httputil.request("follows", params, function (successresult) {
          that.userlist = successresult.user_list
        }, function (errorresult) {

        }, "GET", isShowLoading, "relationlink")
      },
      fetchSaleList(type, isShowLoading, requestStart, done) {
        var that = this
        var params = {};
        params.start = requestStart
        httputil.request("feeds", params, function (successresult) {
          if (successresult.feeds_list.feeds == null) {
            that.isShowFeeds = false
            that.showview = true
            that.has_next = false
            if (type == "down" || type == "up") {
              done();
            }
          }else {
            that.isShowFeeds = true
            that.showview = true
            that.has_next = successresult.feeds_list.has_next == 0 ? false : true;
            if (type == "down" || type == "up") {
              done();
            }
            if (requestStart == "") {
              that.list = successresult.feeds_list.feeds;
            } else {
              that.list = that.list.concat(successresult.feeds_list.feeds);
            }
            if (successresult.feeds_list.feeds.length != 0) {
              that.start = that.list[that.list.length - 1].id
            } else {

            }
          }
          if (that.has_next == false) {

              that.geCommendUserList(false);

          }




        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      async fetch() {
        if (this.needFetch) {
          this.onInit()
          this.vuet.store.relationlink.$scroll.content.y = 0
        }
      },
      onRefresh(done) {
        this.start = ""
        this.userlist = []
        this.fetchSaleList("down", false, this.start, done)
      },
      onGetmore(done) {
        // alert(this.has_next)
        if (this.has_next) {
          this.fetchSaleList("up", false, this.start, done)
        }
      },
      onInit() {
        this.start = ""
        this.list = []
        this.userlist = []
        this.has_next = true
        this.fetchSaleList("init", true, this.start)
      },
    },
    shop: {
      data() {
        return {
          needFetch: true,
          bannerlist: [],
          start: "",
          has_next: true,
          list: []
        }
      },
      skipToGoodsDetail(item) {
        this.needFetch = false
        this.app.$router.push({name: 'goodsdetail', query: {id: item.id}})
      },

      getBannerList(type, done) {
        var that = this;
        httputil.request("banners", {}, function (successresult) {
          if (type == "down") {
            done();
          }
          that.bannerlist = successresult.banners
        }, function (errorresult) {
          if (type == "down") {
            done();
          }
        }, "GET", false, "")
      },
      fetchSaleList(type, isShowLoading, requestStart, done) {
        var that = this
        var params = {};
        params.start = requestStart
        httputil.request("goods/list", params, function (successresult) {
          that.showview = true
          that.has_next = successresult.has_next == 0 ? false : true;
          if (type == "down" || type == "up") {
            done();
          }
          if (requestStart == "") {
            that.list = successresult.goods_list;
          } else {
            that.list = that.list.concat(successresult.goods_list);
          }
          if (successresult.goods_list.length != 0) {
            that.start = that.list[that.list.length - 1].id
            that.current_length = successresult.goods_list.length
          } else {

          }

        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      async fetch() {
        if (this.needFetch) {
          this.onInit()
          this.vuet.store.shop.$scroll.content.y = 0
        }
      },
      onRefresh(done) {
        this.getBannerList("down", done)
        this.start = ""
        this.fetchSaleList("down", false, this.start, done)
      },
      onGetmore(done) {
        // alert(this.has_next)
        if (this.has_next) {
          this.fetchSaleList("up", false, this.start, done)
        }
      },
      onInit() {
        this.getBannerList("init")
        this.start = ""
        this.fetchSaleList("init", false, this.start)
      },
    },
    profile: {
      data() {
        return {
          profile: ""
        }
      },
      route: {
        once: false
      },
      async fetch() {
        var that = this
        if (this.app.$getLoginStatus()) {
          httputil.request("user/profile", {}, function (successresult) {
            that.profile = successresult.user
          }, function (errorresult) {

          }, "GET", false, "")
        }
      },
      skipToUserpage() {
        this.needFetch = false
        this.app.$router.push({name: 'userpage', query: {id: this.profile.id}})
      },
      skipToFansfollowslist(id) {
        this.needFetch = false
        this.app.$router.push({name: 'fansfollowslist', query: {id: id,user_id:0}})
      },
      skipToLogin() {
        this.app.$pushRouteByJson({name: "login"})
      },
      exitLogin() {
        localStorage.removeItem("Accept-Token")
        this.profile = "";
        this.fetch();
      }
    },
    search: {
      data() {
        return {
          searchkeyword:"",
          keywordlist:[],
          isSearchResultPage:false,
          profile: {},
          needFetch: true,
          showview: false,
          apiname: "my/articles",
          page: 1,
          has_next: true,
          list: [],
          topcategory: [{name: "笔记", id: 0, checked: true}, {name: "特惠", id: 1}, {name: "文章", id: 2}, {name: "商品", id: 3}, {name: "用户", id: 4}],
          topid: 0
        }
      },
      deleteSearchkeyword(){
        this.searchkeyword = "";
      },
      getKeyWordList() {
        this.keywordlist = (localStorage.getItem("keywordlist") === null) ? []:JSON.parse(localStorage.getItem("keywordlist"));
      },
      clearKeyWordList() {
        localStorage.removeItem('keywordlist');
        this.keywordlist = (localStorage.getItem("keywordlist") === null) ? []:JSON.parse(localStorage.getItem("keywordlist"));
      },
      searchByHistory(item) {
        this.searchkeyword = item
        this.dosearch()
      },
      dosearch() {
        if (this.searchkeyword.trim() == "") {
          utils.toast("搜索关键词不能为空哦~")
          this.searchkeyword = "";
        } else {
          this.keywordlist.unshift(this.searchkeyword)
          localStorage.setItem("keywordlist", JSON.stringify(this.keywordlist))
          if (this.isSearchResultPage) {
            this.changeCategory(this.topid)
          } else {
            window.location.href = window.location.href + "#searchresultpage";
            this.changeCategory(0)
          }

        }
      },
      skipToUserpage(id) {
        this.needFetch = false
        this.app.$router.push({name: 'userpage', query: {id: id}})
      },
      follow(item) {
        var that = this
        var params = {id: item.id}
        httputil.request("fans/followed", params, function (successresult) {
          item.followed = successresult.followed
        }, function (errorresult) {

        }, "POST", true, "search")
      },
      fetchUserList(type, isShowLoading, done) {
        var that = this
        var params = {};
        params.page = this.page
        params.keywords = this.searchkeyword
        httputil.request("search/user", params, function (successresult) {
          that.showview = true
          that.has_next = successresult.user_list.has_next == 0 ? false : true;
          if (type == "down" || type == "up") {
            done();
          }
          if (that.page == 1) {
            that.vuet.store.search.$scroll.content.y = 0
            that.list = successresult.user_list.users;
          } else {
            that.list = that.list.concat(successresult.user_list.users);
          }
          if (successresult.user_list.users.length != 0) {
            that.page = that.page + 1

          } else {

          }

        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      fetchGoodsList(type, isShowLoading, done) {
        var that = this
        var params = {};
        params.page = this.page
        params.keywords = this.searchkeyword
        httputil.request("search/goods", params, function (successresult) {
          that.showview = true
          that.has_next = successresult.has_next == 0 ? false : true;
          if (type == "down" || type == "up") {
            done();
          }
          if (that.page == 1) {
            that.vuet.store.search.$scroll.content.y = 0
            that.list = successresult.goods;
          } else {
            that.list = that.list.concat(successresult.goods);
          }
          if (successresult.goods.length != 0) {
            that.page = that.page + 1

          } else {

          }

        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      fetchNoteList(type, isShowLoading, done) {
        var that = this
        var params = {};
        params.page = this.page
        params.keywords = this.searchkeyword
        httputil.request("search/note", params, function (successresult) {
          that.showview = true
          that.has_next = successresult.note_list.has_next == 0 ? false : true;
          if (type == "down" || type == "up") {
            done();
          }
          if (that.page == 1) {
            that.vuet.store.search.$scroll.content.y = 0
            that.list = successresult.note_list.notes;
          } else {
            that.list = that.list.concat(successresult.note_list.notes);
          }
          if (successresult.note_list.notes.length != 0) {
            that.page = that.page + 1

          } else {

          }

        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      fetchSaleList(type, isShowLoading, done) {
        var that = this
        var params = {};
        params.page = this.page
        params.keywords = this.searchkeyword
        httputil.request("search/discount", params, function (successresult) {
          that.showview = true
          that.has_next = successresult.discount_list.has_next == 0 ? false : true;
          if (type == "down" || type == "up") {
            done();
          }
          if (that.page == 1) {
            that.vuet.store.search.$scroll.content.y = 0
            that.list = successresult.discount_list.discounts;
          } else {
            that.list = that.list.concat(successresult.discount_list.discounts);
          }
          if (successresult.discount_list.discounts.length != 0) {
            that.page = that.page + 1

          } else {

          }

        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      skipToSaleDetail(item, index) {
        this.needFetch = false
        this.app.$router.push({name: 'saledetail', query: {id: item.id}})

      },
      skipClickBuy(item) {
        this.data.needFetch = false
        if (window.location.href.indexOf(this.app.GLOBAL.skitToThirdWebSign) == -1) {
          window.location.replace(window.location.href + this.app.GLOBAL.skitToThirdWebSign)
        }
        window.location.href = item.link;
      },
      fetchArticleList(type, isShowLoading, done) {
        var that = this
        var params = {};
        params.page = this.page
        params.keywords = this.searchkeyword
        httputil.request("search/article", params, function (successresult) {
          that.showview = true
          that.has_next = successresult.article_list.has_next == 0 ? false : true;
          if (type == "down" || type == "up") {
            done();
          }
          if (that.page == 1) {
            that.vuet.store.search.$scroll.content.y = 0
            that.list = successresult.article_list.articles;
          } else {
            that.list = that.list.concat(successresult.article_list.articles);
          }
          if (successresult.article_list.articles.length != 0) {
            that.page = that.page + 1

          } else {

          }

        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      changeCategory(id) {
        this.topid = id
        this.list = []
        this.showview = false
        this.has_next = true
        this.page = 1
        var changed = this.topcategory
        for (var i = 0; i < changed.length; i++) {
          if (i == id) {
            changed[i].checked = true
          } else {
            changed[i].checked = false
          }
        }

        if (id == 0) {
          this.fetchNoteList("", true)
        } else if (id == 1) {
          this.fetchSaleList("", true)
        } else if (id == 2) {
          this.fetchArticleList("", true)
        }else if (id == 3) {
          this.fetchGoodsList("", true)
        }else if (id == 4) {
          this.fetchUserList("", true)
        }
      },
      async fetch() {
        if (this.needFetch) {
          this.searchkeyword = "";
          this.getKeyWordList();
          this.isSearchResultPage = false
          // this.showview = false
          // this.profile = {}
          // this.list = []
          // this.has_next = true
          // this.changeCategory(1)
          // this.fetchUserinfo()

        }
      },
      onRefresh(done) {
        this.page = 1
        if (this.topid == 0) {
          this.fetchNoteList("down", false, done)
        } else if (this.topid == 1) {
          this.fetchSaleList("down", false, done)
        } else if (this.topid == 2) {
          this.fetchArticleList("down", false, done)
        }else if (this.topid == 3) {
          this.fetchGoodsList("down", false, done)
        }else if (this.topid == 4) {
          this.fetchUserList("down", false, done)
        }

      },
      onGetmore(done) {
        if (this.has_next) {
          if (this.topid == 0) {
            this.fetchNoteList("up", false, done)
          } else if (this.topid == 1) {
            this.fetchSaleList("up", false, done)
          } else if (this.topid == 2) {
            this.fetchArticleList("up", false, done)
          }else if (this.topid == 3) {
            this.fetchGoodsList("up", false, done)
          }else if (this.topid == 4) {
            this.fetchUserList("up", false, done)
          }
        }
      },
    },
    userpage: {
      data() {
        return {
          profile: {},
          needFetch: true,
          showview: false,
          apiname: "my/articles",
          start: 0,
          has_next: true,
          list: [],
          topcategory: [{name: "笔记", id: 0, checked: true}, {name: "特惠", id: 1}, {name: "文章", id: 2}],
          topid: 1
        }
      },
      fetchUserinfo() {
        var that = this
        httputil.request("user/profile", {id: this.app.$route.query.id}, function (successresult) {
          that.profile = successresult.user
        }, function (errorresult) {

        }, "GET", true, "")
      },
      follow() {
        var that = this
        // if (this.app.$getLoginStatus()) {
        //   if (this.profile.followed == 0) {
        //     this.profile.followed = 1
        //   } else {
        //     this.profile.followed = 0
        //   }
        // }
        var params = {id: this.app.$route.query.id}
        httputil.request("fans/followed", params, function (successresult) {
          that.profile.followed = successresult.followed
        }, function (errorresult) {

        }, "POST", true, "userpage")
      },
      skipToFansfollowslist(id) {
        this.needFetch = false
        this.app.$router.push({name: 'fansfollowslist', query: {id: id,user_id:this.app.$route.query.id}})
      },
      fetchNoteList(type, isShowLoading, done) {
        var that = this
        var params = {};
        params.start = this.start
        params.user_id = this.app.$route.query.id
        httputil.request("user/notes", params, function (successresult) {
          that.showview = true
          that.has_next = successresult.note_list.has_next == 0 ? false : true;
          if (type == "down" || type == "up") {
            done();
          }
          if (that.start == 0) {
            that.vuet.store.userpage.$scroll.content.y = 0
            that.list = successresult.note_list.notes;
          } else {
            that.list = that.list.concat(successresult.note_list.notes);
          }
          if (successresult.note_list.notes.length != 0) {
            that.start = that.list[that.list.length - 1].id

          } else {

          }

        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      fetchSaleList(type, isShowLoading, done) {
        var that = this
        var params = {};
        params.start = this.start
        params.id = this.app.$route.query.id
        httputil.request("user/discounts", params, function (successresult) {
          that.showview = true
          that.has_next = successresult.discount_list.has_next == 0 ? false : true;
          if (type == "down" || type == "up") {
            done();
          }
          if (that.start == 0) {
            that.vuet.store.userpage.$scroll.content.y = 0
            that.list = successresult.discount_list.discounts;
          } else {
            that.list = that.list.concat(successresult.discount_list.discounts);
          }
          if (successresult.discount_list.discounts.length != 0) {
            that.start = that.list[that.list.length - 1].id

          } else {

          }

        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      skipToSaleDetail(item, index) {
        this.needFetch = false
        this.app.$router.push({name: 'saledetail', query: {id: item.id}})

      },
      skipClickBuy(item) {
        this.data.needFetch = false
        if (window.location.href.indexOf(this.app.GLOBAL.skitToThirdWebSign) == -1) {
          window.location.replace(window.location.href + this.app.GLOBAL.skitToThirdWebSign)
        }
        window.location.href = item.link;
      },
      fetchArticleList(type, isShowLoading, done) {
        var that = this
        var params = {};
        params.start = this.start
        params.id = this.app.$route.query.id
        httputil.request("user/articles", params, function (successresult) {
          that.showview = true
          that.has_next = successresult.article_list.has_next == 0 ? false : true;
          if (type == "down" || type == "up") {
            done();
          }
          if (that.start == 0) {
            that.vuet.store.userpage.$scroll.content.y = 0
            that.list = successresult.article_list.articles;
          } else {
            that.list = that.list.concat(successresult.article_list.articles);
          }
          if (successresult.article_list.articles.length != 0) {
            that.start = that.list[that.list.length - 1].id

          } else {

          }

        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      skipToArticle(id) {
        this.needFetch = false
        this.app.$router.push({name: 'contentdetail', query: {id: id}})

      },
      changeCategory(id) {
        this.topid = id
        this.list = []
        var changed = this.topcategory
        for (var i = 0; i < changed.length; i++) {
          if (i == id) {
            changed[i].checked = true
          } else {
            changed[i].checked = false
          }
        }
        this.start = 0
        if (id == 0) {
          this.fetchNoteList("", true)
        } else if (id == 1) {
          this.fetchSaleList("", true)
        } else if (id == 2) {
          this.fetchArticleList("", true)
        }
        // this.fetchList("", true)
      },
      fetchList(type, isShowLoading, done) {
        var that = this
        var params = {};
        params.start = this.start
        params.time = this.time
        httputil.request(this.apiname, params, function (successresult) {
          that.showview = true
          that.has_next = successresult.article_list.has_next == 0 ? false : true;
          if (type == "down" || type == "up") {
            done();
          }
          if (that.start == 0) {
            that.vuet.store.profilearticle.$scroll.content.y = 0
            that.list = successresult.article_list.articles;
          } else {
            that.list = that.list.concat(successresult.article_list.articles);
          }
          if (successresult.article_list.articles.length != 0) {
            that.start = that.list[that.list.length - 1].id
            if (that.apiname == "like/articles") {
              that.time = that.list[that.list.length - 1].like_at
            } else if (that.apiname == "collect/articles") {
              that.time = that.list[that.list.length - 1].collect_at
            }

          } else {

          }

        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      async fetch() {
        this.showview = false
        this.profile = {}
        this.list = []
        this.has_next = true
        this.changeCategory(0)
        this.fetchUserinfo()
        // if (this.needFetch) {
        //   this.showview = false
        //   this.profile = {}
        //   this.list = []
        //   this.has_next = true
        //   this.changeCategory(0)
        //   this.fetchUserinfo()
        //
        // }
      },
      onRefresh(done) {
        this.start = 0
        this.fetchUserinfo()
        if (this.topid == 0) {
          this.fetchNoteList("down", false, done)
        } else if (this.topid == 1) {
          this.fetchSaleList("down", false, done)
        } else if (this.topid == 2) {
          this.fetchArticleList("down", false, done)
        }

      },
      onGetmore(done) {
        if (this.has_next) {
          if (this.topid == 0) {
            this.fetchNoteList("up", false, done)
          } else if (this.topid == 1) {
            this.fetchSaleList("up", false, done)
          } else if (this.topid == 2) {
            this.fetchArticleList("up", false, done)
          }
        }
      },
      // onInit() {
      //   this.start = 0
      //   this.time = 0
      //   this.topcategory = [{name:"全部",id:0,checked:true}]
      //   this.cat_id = 0
      //   this.list = []
      //   this.showview = false
      //   this.fetchSaleList("init", true)
      // },
    },
    fansfollowslist: {
      data() {
        return {
          needFetch: true,
          showview: false,
          apiname: "user/follows",
          start: 0,
          has_next: true,
          list: [],
          topcategory: [{name: "关注", id: 0, checked: true}, {name: "粉丝", id: 1}],
        }
      },
      skipToUserpage(id) {
        this.needFetch = false
        this.app.$router.push({name: 'userpage', query: {id: id}})
      },
      follow(id) {
        var that = this
        var params = {id: id}
        httputil.request("fans/followed", params, function (successresult) {
          for (var j = 0; j < that.list.length; j++) {
            if (id == that.list[j].id) {
              Vue.set(that.list[j], 'followed', successresult.followed)
            }
          }
        }, function (errorresult) {

        }, "POST", true, "fansfollowslist")
      },
      skipToArticle(id) {
        this.needFetch = false
        this.app.$router.push({name: 'contentdetail', query: {id: id}})

      },
      changeCategory(id) {
        var changed = this.topcategory
        for (var i = 0; i < changed.length; i++) {
          if (i == id) {
            changed[i].checked = true
          } else {
            changed[i].checked = false
          }
        }
        this.start = 0
        if (id == 0) {
          this.apiname = "user/follows"
        } else if (id == 1) {
          this.apiname = "user/fans"
        }
        this.fetchList("", true)
      },
      fetchList(type, isShowLoading, done) {
        var that = this
        var params = {};
        params.start = this.start
        params.user_id = this.app.$route.query.user_id
        httputil.request(this.apiname, params, function (successresult) {
          that.showview = true
          that.has_next = successresult.user_list.has_next == 0 ? false : true;
          if (type == "down" || type == "up") {
            done();
          }
          if (that.start == 0) {
            that.vuet.store.fansfollowslist.$scroll.content.y = 0
            that.list = successresult.user_list.users;
          } else {
            that.list = that.list.concat(successresult.user_list.users);
          }
          if (successresult.user_list.users.length != 0) {
            that.start = that.list[that.list.length - 1].id
          } else {

          }

        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      async fetch() {
        this.changeCategory(this.app.$route.query.id)
        this.list = []
        this.showview = false
        // if (this.needFetch) {
        //   this.changeCategory(this.app.$route.query.id)
        //   this.list = []
        //   this.showview = false
        // }
      },
      onRefresh(done) {
        this.start = 0
        this.fetchList("down", false, done)
      },
      onGetmore(done) {
        if (this.has_next) {
          this.fetchList("up", false, done)
        }
      },
    },
    sale: {
      data() {
        return {
          windowHeight: 1,
          index: 0,
          distance: 0,//手指在页面滑动的距离
          nowTop: {
            before: -this.windowHeight,
            current: 0,
            next: this.windowHeight
          },
          nowTransition: {
            self: 0,
            others: 0
          },

          touchStart: 0,
          canmove: true,
          hasStart: true,
          pullupTime: 0.3,
          rebackTime: 0.2,
          list: [],
          hasNext: true,
          start: "",
          preloadLength: 10,
          needFetch: true,
          preFetchFinished: true,
          switchdistance: 1,


          downFreshDistance: -1,
          downFreshDes: "下拉刷新"
        }
      },
      // route: {
      //   once: true // 当前页面，只加载一次，这样我们就可以做上拉加载了
      // },

      top(i) {
        var topValue = 0;
        if (i == this.index) {
          topValue = this.nowTop.current;
        } else if (i == this.index - 1) {
          topValue = this.nowTop.before;
        } else if (i == this.index + 1) {
          topValue = this.nowTop.next
        } else {
          topValue = (i - this.index) * this.windowHeight
        }
        return topValue + 'px'
      },
      transition(i) {
        var transitionVal = 0;
        if (i == this.index - 1 || i == this.index || i == this.index + 1) {
          transitionVal = this.nowTransition.self
        } else {
          transitionVal = this.nowTransition.others
        }
        return transitionVal
      },
      skipToLogin() {
        setTimeout(() => {
          this.app.$pushRouteByJson({name: "login"})
        }, 1)
        this.needFetch = false
      },
      panStart(e) {
        e.preventDefault();
        this.hasStart = true;
        if (!this.canmove) {
          this.hasStart = false;
          return false
        }
        this.distance = 0;
        this.nowTop = {
          before: -this.windowHeight,
          current: 0,
          next: this.windowHeight,
        }
        this.nowTransition = {
          self: 0,
          others: 0
        }
        this.touchStart = e.center.y;

      },
      panMove(e) {
        e.preventDefault();
        if (this.hasStart) {
          if (!this.canmove && this.touchStart == 0) {
            return false
          } else {
            this.distance = e.center.y - this.touchStart;
            //第一页不能下滑翻页，最后一页不能上滑翻页

            if (!((this.index == 0 && this.distance > 0) || ((this.index == this.list.length - 1) && this.distance < 0))) {
              this.nowTop = {
                before: -this.windowHeight + this.distance,
                current: this.distance,
                next: this.windowHeight + this.distance,
              }
            } else {
              this.downFreshDistance = this.distance / this.app.GLOBAL.ratio - 1;
              if (this.downFreshDistance < 0) {
                this.downFreshDes = "下拉刷新"
              } else {
                this.downFreshDes = "释放刷新"
              }
            }
          }
        }


      },
      panEnd(e) {
        e.preventDefault();
        if (this.hasStart) {
          if (!this.canmove || this.touchStart == 0) {
            return
          }
          if (!((this.index == 0 && this.distance > 0) || (this.index == this.list.length - 1 && this.distance < 0))) {
            this.touchStart = 0;

            if (this.distance > 0 && this.distance > this.switchdistance) {//可以下滑
              this.distance = 0;
              this.canmove = false;
              this.nowTop = {
                before: 0,
                current: this.windowHeight,
                next: 2 * this.windowHeight
              }
              this.nowTransition = {
                self: this.pullupTime,
                others: 0
              }
              setTimeout(() => {
                this.nowTop = {
                  before: -this.windowHeight,
                  current: 0,
                  next: this.windowHeight,
                  others: 0
                }
                this.nowTransition = {
                  self: 0,
                  others: 0
                }
                this.index--;
                // this.canRequest()
                this.canmove = true;

              }, this.pullupTime * 1000)
//            $(this.$refs[`touch${this.index}`][0]).addClass('animated').siblings().removeClass('animated');
//            var obj = {
//              hasAnimats:true,
//              name:`touch${this.index-1}`
//            }
//            this.$store.commit('showAnimation',obj)

            } else if (this.distance > 0 && this.distance < this.switchdistance) {//不可以下滑
              this.distance = 0;
              this.canmove = false;
              this.nowTop = {
                before: -this.windowHeight,
                current: 0,
                next: this.windowHeight
              }
              this.nowTransition = {
                self: this.rebackTime,
                others: 0
              }
              setTimeout(() => {
                this.nowTransition = {
                  self: 0,
                  others: 0
                }
                this.canmove = true
              }, this.rebackTime * 1000)

            } else if (this.distance < 0 && this.distance * (-1) > this.switchdistance) {//可以上滑
              this.distance = 0;
              this.canmove = false;
              this.nowTop = {
                before: -2 * this.windowHeight,
                current: -this.windowHeight,
                next: 0
              }
              this.nowTransition = {
                self: this.pullupTime,
                others: 0
              }
              setTimeout(() => {
                this.nowTop = {
                  before: -this.windowHeight,
                  current: 0,
                  next: this.windowHeight
                }
                this.nowTransition = {
                  self: 0,
                  others: 0
                }
                this.index++;
                this.canRequest()
                this.canmove = true;
                this.reportReadSale();
              }, this.pullupTime * 1000)
//            $(this.$refs[`touch${this.index}`][0]).addClass('animated').siblings().removeClass('animated');
//            var obj = {
//              hasAnimats:true,
//              name:`touch${this.index+1}`
//            }
//            this.$store.commit('showAnimation',obj)
            } else if (this.distance < 0 && this.distance * (-1) < this.switchdistance) {//不可以上滑
              this.distance = 0;
              this.canmove = false;
              this.nowTop = {
                before: -this.windowHeight,
                current: 0,
                next: this.windowHeight
              }
              this.nowTransition = {
                self: this.rebackTime,
                others: 0
              }
              setTimeout(() => {
                this.nowTransition = {
                  self: 0,
                  others: 0
                }
                this.canmove = true;
              }, this.rebackTime * 1000)

            }
          } else {
            this.nowTop = {
              before: -this.windowHeight,
              current: 0,
              next: this.windowHeight
            }
            if (this.downFreshDistance > 0) {
              this.downFreshDes = "加载中..."
              this.start = "";
              this.index = 0;
              this.nowTop.before = -this.windowHeight
              this.nowTop.current = 0
              this.nowTop.next = this.windowHeight
              this.fetchSaleList(false, this.start)
            } else {
              this.downFreshDes = "下拉刷新"
              this.downFreshDistance = -1
            }
          }
        }
      },
      async fetch() {
        if (this.needFetch) {
          this.start = "";
          this.index = 0;
          this.list = [];
          this.fetchSaleList(true, this.start);
        }
        this.pullupTime = 0.3
        this.rebackTime = 0.2
        this.nowTop = {
          before: -this.windowHeight,
          current: 0,
          next: this.windowHeight
        }
        this.nowTransition = {
          self: 0,
          others: 0
        }
        this.touchStart = 0
        this.canmove = true
        this.hasStart = true
        this.downFreshDistance = -1
        this.downFreshDes = "下拉刷新"
        this.preFetchFinished = true
      },
      canRequest() {
        if (this.list.length - this.index <= this.preloadLength && this.preFetchFinished) {
          this.preFetchFinished = false

          if (this.hasNext) {
            // setTimeout( () => {this.fetchSaleList(false,this.start)},8000);

            this.fetchSaleList(false, this.start)
          } else {
            if (this.index + 1 == this.list.length) {
              utils.toast("已经是最后一条信息啦")
            }
          }
        }
      },
      fetchSaleList(isShowLoading, requestStart) {
        var that = this
        var params = {start: requestStart}

        httputil.request("discount/unread", params, function (successresult) {
          // document.getElementById("mysale").src = "/static/sale_selected.png"
          that.downFreshDistance = -1
          that.preFetchFinished = true
          if (requestStart == "") {
            that.list = [];
          }
          that.hasNext = successresult.discount_list.has_next
          if (successresult.discount_list.discounts.length != 0) {
            that.start = successresult.discount_list.discounts[successresult.discount_list.discounts.length - 1].id
            if (requestStart == "") {
              that.list = successresult.discount_list.discounts;
              that.reportReadSale();
              that.canRequest();
            } else {
              that.list = that.list.concat(successresult.discount_list.discounts);
            }


            // var idlist = [];
            // for (var i = 0;i<successresult.discounts.length;i++) {
            //   idlist.push(successresult.discounts[i].id)
            // }
            // that.getSaleCollectedList(idlist.join(","))
          }
        }, function (errorresult) {
          that.preFetchFinished = true
          // document.getElementById("mysale").src = "/static/sale_selected.png"
        }, "GET", isShowLoading)
      },
      getSaleCollectedList(ids) {
        var that = this
        var params = {ids: ids}
        httputil.request("collect/discount", params, function (successresult) {
          for (var i = 0; i < successresult.collects.length; i++) {
            for (var j = 0; j < that.list.length; j++) {
              if (successresult.collects[i].id == that.list[j].id) {
                that.list[j].collected = successresult.collects[i].collected
              }
            }
          }
          that.nowTop = {
            before: -that.windowHeight,
            current: 0,
            next: that.windowHeight,
          }
        }, function (errorresult) {

        }, "GET", false)
      },
      collect(sale) {
        var that = this
        if (this.app.$getLoginStatus()) {
          sale.collected == 0 ? sale.collected = 1 : sale.collected = 0
          that.nowTop = {
            before: -that.windowHeight,
            current: 0,
            next: that.windowHeight,
          }
        }

        var params = {discount_id: sale.id}
        httputil.request("collect/discount", params, function (successresult) {
          for (var j = 0; j < that.list.length; j++) {
            if (sale.id == that.list[j].id) {
              Vue.set(that.list[j], 'collected', successresult.collected)
            }
          }
          that.nowTop = {
            before: -that.windowHeight,
            current: 0,
            next: that.windowHeight,
          }
        }, function (errorresult) {

        }, "POST", false, "sale")
      },

      skip(sale) {
        this.needFetch = false
        this.preFetchFinished = true
        if (window.location.href.indexOf(this.app.GLOBAL.skitToThirdWebSign) == -1) {
          window.location.replace(window.location.href + this.app.GLOBAL.skitToThirdWebSign)
        }
        window.location.href = sale.link;
      },
      reportReadSale() {
        if (this.app.$getLoginStatus()) {
          var that = this
          if (this.list[this.index] != null) {
            var params = {ids: this.list[this.index].id}
            httputil.request("discounts/report", params, function (successresult) {

            }, function (errorresult) {

            }, "POST", false)
          }
        }
      },
    },
    profilenote: {
      data() {
        return {
          needFetch: true,
          showview: false,
          apiname: "my/notes",
          start: 0,
          time: 0,
          has_next: true,
          list: [],
          topcategory: [{name: "发布", id: 0, checked: true}, {name: "喜欢", id: 1}, {name: "收藏", id: 2}],
        }
      },
      skipToArticle(id) {
        this.needFetch = false
        this.app.$router.push({name: 'contentdetail', query: {id: id}})

      },
      changeCategory(id) {
        var changed = this.topcategory
        for (var i = 0; i < changed.length; i++) {
          if (i == id) {
            changed[i].checked = true
          } else {
            changed[i].checked = false
          }
        }
        this.start = 0
        this.time = 0
        if (id == 0) {
          this.apiname = "my/notes"
        } else if (id == 1) {
          this.apiname = "like/notes"
        } else if (id == 2) {
          this.apiname = "collect/notes"
        }
        this.fetchList("", true)
      },
      fetchList(type, isShowLoading, done) {
        var that = this
        var params = {};
        params.start = this.start
        params.time = this.time
        httputil.request(this.apiname, params, function (successresult) {
          that.showview = true
          that.has_next = successresult.note_list.has_next == 0 ? false : true;
          if (type == "down" || type == "up") {
            done();
          }
          if (that.start == 0) {
            that.vuet.store.profilenote.$scroll.content.y = 0
            that.list = successresult.note_list.notes;
          } else {
            that.list = that.list.concat(successresult.note_list.notes);
          }
          if (successresult.note_list.notes.length != 0) {
            that.start = that.list[that.list.length - 1].id
            if (that.apiname == "like/notes") {
              that.time = that.list[that.list.length - 1].like_at
            } else if (that.apiname == "collect/notes") {
              that.time = that.list[that.list.length - 1].collect_at
            }

          } else {

          }

        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      async fetch() {
        if (this.needFetch) {
          this.changeCategory(this.app.$route.query.id)
          this.list = []
          this.showview = false
        }
      },
      onRefresh(done) {
        this.start = 0
        this.time = 0
        this.fetchList("down", false, done)
      },
      onGetmore(done) {
        if (this.has_next) {
          this.fetchList("up", false, done)
        }
      },
      // onInit() {
      //   this.start = 0
      //   this.time = 0
      //   this.topcategory = [{name:"全部",id:0,checked:true}]
      //   this.cat_id = 0
      //   this.list = []
      //   this.showview = false
      //   this.fetchSaleList("init", true)
      // },
    },
    profilearticle: {
      data() {
        return {
          needFetch: true,
          showview: false,
          apiname: "my/articles",
          start: 0,
          time: 0,
          has_next: true,
          list: [],
          topcategory: [{name: "发布", id: 0, checked: true}, {name: "喜欢", id: 1}, {name: "收藏", id: 2}],
        }
      },
      skipToArticle(id) {
        this.needFetch = false
        this.app.$router.push({name: 'contentdetail', query: {id: id}})

      },
      changeCategory(id) {
        var changed = this.topcategory
        for (var i = 0; i < changed.length; i++) {
          if (i == id) {
            changed[i].checked = true
          } else {
            changed[i].checked = false
          }
        }
        this.start = 0
        this.time = 0
        if (id == 0) {
          this.apiname = "my/articles"
        } else if (id == 1) {
          this.apiname = "like/articles"
        } else if (id == 2) {
          this.apiname = "collect/articles"
        }
        this.fetchList("", true)
      },
      fetchList(type, isShowLoading, done) {
        var that = this
        var params = {};
        params.start = this.start
        params.time = this.time
        httputil.request(this.apiname, params, function (successresult) {
          that.showview = true
          that.has_next = successresult.article_list.has_next == 0 ? false : true;
          if (type == "down" || type == "up") {
            done();
          }
          if (that.start == 0) {
            that.vuet.store.profilearticle.$scroll.content.y = 0
            that.list = successresult.article_list.articles;
          } else {
            that.list = that.list.concat(successresult.article_list.articles);
          }
          if (successresult.article_list.articles.length != 0) {
            that.start = that.list[that.list.length - 1].id
            if (that.apiname == "like/articles") {
              that.time = that.list[that.list.length - 1].like_at
            } else if (that.apiname == "collect/articles") {
              that.time = that.list[that.list.length - 1].collect_at
            }

          } else {

          }

        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      async fetch() {
        if (this.needFetch) {
          this.changeCategory(this.app.$route.query.id)
          this.list = []
          this.showview = false
        }
      },
      onRefresh(done) {
        this.start = 0
        this.time = 0
        this.fetchList("down", false, done)
      },
      onGetmore(done) {
        if (this.has_next) {
          this.fetchList("up", false, done)
        }
      },
      // onInit() {
      //   this.start = 0
      //   this.time = 0
      //   this.topcategory = [{name:"全部",id:0,checked:true}]
      //   this.cat_id = 0
      //   this.list = []
      //   this.showview = false
      //   this.fetchSaleList("init", true)
      // },
    },
    profilesale: {
      data() {
        return {
          needFetch: true,
          showview: false,
          apiname: "my/discounts",
          start: 0,
          time: 0,
          has_next: true,
          list: [],
          topcategory: [{name: "爆料", id: 0, checked: true}, {name: "已抢", id: 1}, {name: "收藏", id: 2}],
        }
      },
      skipToDetail(item, index) {
        this.needFetch = false
        this.app.$router.push({name: 'saledetail', query: {id: item.id}})

      },
      skipClickBuy(item) {
        this.data.needFetch = false
        if (window.location.href.indexOf(this.app.GLOBAL.skitToThirdWebSign) == -1) {
          window.location.replace(window.location.href + this.app.GLOBAL.skitToThirdWebSign)
        }
        window.location.href = item.link;
      },
      changeCategory(id) {
        var changed = this.topcategory
        for (var i = 0; i < changed.length; i++) {
          if (i == id) {
            changed[i].checked = true
          } else {
            changed[i].checked = false
          }
        }
        this.start = 0
        this.time = 0
        if (id == 0) {
          this.apiname = "my/discounts"
        } else if (id == 1) {
          this.apiname = "like/discounts"
        } else if (id == 2) {
          this.apiname = "collect/discounts"
        }
        this.fetchList("", true)
      },
      fetchList(type, isShowLoading, done) {
        var that = this
        var params = {};
        if (this.apiname == "my/discounts" || this.apiname == "like/discounts") {
          params.start = this.start
        } else {
          params.discount_id = this.start
          params.collect_time = this.time
        }
        httputil.request(this.apiname, params, function (successresult) {
          if (that.apiname == "my/discounts" || that.apiname == "like/discounts") {
            that.showview = true
            that.has_next = successresult.discount_list.has_next == 0 ? false : true;
            if (type == "down" || type == "up") {
              done();
            }
            if (that.start == 0) {
              that.vuet.store.profilesale.$scroll.content.y = 0
              that.list = successresult.discount_list.discounts;
            } else {
              that.list = that.list.concat(successresult.discount_list.discounts);
            }
            if (successresult.discount_list.discounts.length != 0) {
              that.start = that.list[that.list.length - 1].id

            } else {

            }
          } else {
            that.showview = true
            that.has_next = successresult.collect_list.has_next == 0 ? false : true;
            if (type == "down" || type == "up") {
              done();
            }
            if (that.start == 0) {
              that.vuet.store.profilesale.$scroll.content.y = 0
              that.list = successresult.collect_list.discounts;
            } else {
              that.list = that.list.concat(successresult.collect_list.discounts);
            }
            if (successresult.collect_list.discounts.length != 0) {
              that.start = that.list[that.list.length - 1].id
              that.time = that.list[that.list.length - 1].collect_time
            } else {

            }
          }


        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      async fetch() {
        if (this.needFetch) {
          this.changeCategory(this.app.$route.query.id)
          this.list = []
          this.showview = false
        }
      },
      onRefresh(done) {
        this.start = 0
        this.time = 0
        this.fetchList("down", false, done)
      },
      onGetmore(done) {
        if (this.has_next) {
          this.fetchList("up", false, done)
        }
      },
      // onInit() {
      //   this.start = 0
      //   this.time = 0
      //   this.topcategory = [{name:"全部",id:0,checked:true}]
      //   this.cat_id = 0
      //   this.list = []
      //   this.showview = false
      //   this.fetchSaleList("init", true)
      // },
    },
    saledetail: {
      data() {
        return {
          windowHeight: 1,
          id: 0,
          detail: {},
          needFetch: true
        }
      },

      async fetch() {
        var that = this
        this.detail = {}
        this.windowHeight = window.innerHeight
        this.id = this.app.$route.query.id
        var params = {id: this.id}
        httputil.request("discount/detail", params, function (successresult) {
          that.detail = successresult.discount
        }, function (errorresult) {

        }, "GET", true)
      },
      collect(sale) {
        var that = this
        if (this.app.$getLoginStatus()) {
          sale.collected == 0 ? sale.collected = 1 : sale.collected = 0
        }
        var params = {discount_id: sale.id}
        httputil.request("collect/discount", params, function (successresult) {
          sale.collected = successresult.collected
        }, function (errorresult) {

        }, "POST", false, "saledetail")
      },
      skip(sale) {
        // this.needFetch = false
        if (window.location.href.indexOf(this.app.GLOBAL.skitToThirdWebSign) == -1) {
          window.location.replace(window.location.href + this.app.GLOBAL.skitToThirdWebSign)
        }
        window.location.href = sale.link;
      }
    },
    salefilter: {
      data() {
        return {
          platformHeight: 2.86,
          platformY: -this.platformHeight,
          platformTime: 0,
          platformList: [{id: 0, name: "全部平台"}],
          platformstatus: 0,
          selectedPlatform: {},

          categoryY: -this.platformHeight,
          categoryTime: 0,
          categoryList: [{id: 0, name: "全部品类"}],
          categorystatus: 0,
          selectedCategory: {},


          backgroundDisplay: "hidden",
          fullscreenheight: "0rem",
          opacity: 0,
          list: [],
          has_next: true,
          start: "",
          current_length: 0,
          needFetch: true,
          showview: false,
        }
      },
      // route: {
      //   once: false // 当前页面，只加载一次，这样我们就可以做上拉加载了
      // },
      pushdownPlatform() {
        if (this.platformstatus == 0) {
          if (this.categorystatus == 1) {
            this.categoryY = -this.platformHeight;
            this.categoryTime = 0;
            this.categorystatus = 0;
          }
          this.platformY = 0;
          this.platformTime = 0.3;
          this.opacity = 0.5;
          this.backgroundDisplay = "visible"
          this.platformstatus = 1;
        } else if (this.platformstatus == 1) {
          this.platformY = -this.platformHeight;
          this.platformTime = 0.3;
          this.opacity = 0;
          setTimeout(() => {
            this.backgroundDisplay = "hidden"
          }, 300)
          this.platformstatus = 0;
        }
      },
      pushdownCategory() {
        if (this.categorystatus == 0) {
          if (this.platformstatus == 1) {
            this.platformY = -this.platformHeight;
            this.platformTime = 0.3;
            this.platformstatus = 0;
          }
          this.categoryY = 0;
          this.categoryTime = 0.3;
          this.opacity = 0.5;
          this.backgroundDisplay = "visible"
          this.categorystatus = 1;
        } else if (this.categorystatus == 1) {
          this.categoryY = -this.platformHeight;
          this.categoryTime = 0.3;
          this.opacity = 0;
          setTimeout(() => {
            this.backgroundDisplay = "hidden"
          }, 300)
          this.categorystatus = 0;
        }
      },
      hiddenBackground() {
        this.platformY = -this.platformHeight;
        this.platformTime = 0.3;
        this.opacity = 0;
        setTimeout(() => {
          this.backgroundDisplay = "hidden"
        }, 300)
        this.platformstatus = 0;
        this.categoryY = -this.platformHeight;
        this.categoryTime = 0.3;
        this.categorystatus = 0;
      },

      // choosePlatform(platform){
      //   this.pushdownPlatform()
      //   if (platform.id != this.selectedPlatform.id) {
      //     this.selectedPlatform = platform
      //     this.start = "";
      //     this.fetchSaleList(true,this.start)
      //     // this.downCallback(this.mescroll)
      //   }
      // },
      // chooseCategory(category){
      //   this.pushdownCategory()
      //   if (category.id != this.selectedCategory.id) {
      //     this.selectedCategory = category
      //     // this.downCallback(this.mescroll)
      //     this.start = "";
      //     this.fetchSaleList(true,this.start)
      //   }
      // },
      async fetch() {
        if (this.needFetch) {
          var that = this
          this.platformY = -this.platformHeight
          this.platformTime = 0
          this.platformList = [{id: 0, name: "全部平台"}]
          this.platformstatus = 0


          this.categoryY = -this.platformHeight
          this.categoryTime = 0
          this.categoryList = [{id: 0, name: "全部品类"}]
          this.categorystatus = 0


          this.backgroundDisplay = "hidden"
          this.fullscreenheight = "0rem"
          this.opacity = 0
          this.list = []
          this.has_next = true
          this.start = ""
          this.current_length = 0
          this.showview = false

          that.selectedPlatform = that.platformList[0];
          that.selectedCategory = that.categoryList[0];
          httputil.request("categories", {}, function (successresult) {
            that.platformList = that.platformList.concat(successresult.platforms);
            that.categoryList = that.categoryList.concat(successresult.categories);
          }, function (errorresult) {

          }, "GET", true)
        }

      },
    },
    salelist: {
      data() {
        return {
          windowHeight: 1,
          index: 0,
          distance: 0,//手指在页面滑动的距离
          nowTop: {
            before: -this.windowHeight,
            current: 0,
            next: this.windowHeight
          },
          nowTransition: {
            self: 0,
            others: 0
          },

          touchStart: 0,
          canmove: true,
          hasStart: true,
          pullupTime: 0.3,
          rebackTime: 0.2,
          list: [],
          hasNext: true,
          start: "",
          selectedPlatform: {},
          selectedCategory: {},
          preloadLength: 10,
          enterParams: "",
          preFetchFinished: true,

          needFetch: true,
        }
      },

      top(i) {
        var topValue = 0;
        if (i == this.index) {
          topValue = this.nowTop.current;
        } else if (i == this.index - 1) {
          topValue = this.nowTop.before;
        } else if (i == this.index + 1) {
          topValue = this.nowTop.next
        } else {
          topValue = (i - this.index) * this.windowHeight
        }
        return topValue + 'px'
      },
      transition(i) {
        var transitionVal = 0;
        if (i == this.index - 1 || i == this.index || i == this.index + 1) {
          transitionVal = this.nowTransition.self
        } else {
          transitionVal = this.nowTransition.others
        }
        return transitionVal
      },

      panStart(e) {
        e.preventDefault();
        this.hasStart = true;
        if (!this.canmove) {
          this.hasStart = false;
          return false
        }
        this.distance = 0;
        this.nowTop = {
          before: -this.windowHeight,
          current: 0,
          next: this.windowHeight,
        }
        this.nowTransition = {
          self: 0,
          others: 0
        }
        this.touchStart = e.center.y;

      },
      panMove(e) {
        e.preventDefault();
        if (this.hasStart) {
          if (!this.canmove && this.touchStart == 0) {
            return false
          } else {
            this.distance = e.center.y - this.touchStart;
            //第一页不能下滑翻页，最后一页不能上滑翻页

            if (!((this.index == 0 && this.distance > 0) || ((this.index == this.list.length - 1) && this.distance < 0))) {
              this.nowTop = {
                before: -this.windowHeight + this.distance,
                current: this.distance,
                next: this.windowHeight + this.distance,
              }
            } else {

            }
          }
        }


      },
      panEnd(e) {
        e.preventDefault();
        if (this.hasStart) {
          if (!this.canmove || this.touchStart == 0) {
            return
          }
          if (!((this.index == 0 && this.distance > 0) || (this.index == this.list.length - 1 && this.distance < 0))) {
            this.touchStart = 0;

            if (this.distance > 0 && this.distance > this.windowHeight / 10) {//可以下滑
              this.distance = 0;
              this.canmove = false;
              this.nowTop = {
                before: 0,
                current: this.windowHeight,
                next: 2 * this.windowHeight
              }
              this.nowTransition = {
                self: this.pullupTime,
                others: 0
              }
              setTimeout(() => {
                this.nowTop = {
                  before: -this.windowHeight,
                  current: 0,
                  next: this.windowHeight,
                  others: 0
                }
                this.nowTransition = {
                  self: 0,
                  others: 0
                }
                this.index--;
                // this.canRequest()
                this.canmove = true;

              }, this.pullupTime * 1000)
//            $(this.$refs[`touch${this.index}`][0]).addClass('animated').siblings().removeClass('animated');
//            var obj = {
//              hasAnimats:true,
//              name:`touch${this.index-1}`
//            }
//            this.$store.commit('showAnimation',obj)

            } else if (this.distance > 0 && this.distance < this.windowHeight / 10) {//不可以下滑
              this.distance = 0;
              this.canmove = false;
              this.nowTop = {
                before: -this.windowHeight,
                current: 0,
                next: this.windowHeight
              }
              this.nowTransition = {
                self: this.rebackTime,
                others: 0
              }
              setTimeout(() => {
                this.nowTransition = {
                  self: 0,
                  others: 0
                }
                this.canmove = true
              }, this.rebackTime * 1000)

            } else if (this.distance < 0 && this.distance * (-1) > this.windowHeight / 10) {//可以上滑
              this.distance = 0;
              this.canmove = false;
              this.nowTop = {
                before: -2 * this.windowHeight,
                current: -this.windowHeight,
                next: 0
              }
              this.nowTransition = {
                self: this.pullupTime,
                others: 0
              }
              setTimeout(() => {
                this.nowTop = {
                  before: -this.windowHeight,
                  current: 0,
                  next: this.windowHeight
                }
                this.nowTransition = {
                  self: 0,
                  others: 0
                }
                this.index++;
                this.canRequest()
                this.canmove = true;
                // this.reportReadSale();
              }, this.pullupTime * 1000)
//            $(this.$refs[`touch${this.index}`][0]).addClass('animated').siblings().removeClass('animated');
//            var obj = {
//              hasAnimats:true,
//              name:`touch${this.index+1}`
//            }
//            this.$store.commit('showAnimation',obj)
            } else if (this.distance < 0 && this.distance * (-1) < this.windowHeight / 10) {//不可以上滑
              this.distance = 0;
              this.canmove = false;
              this.nowTop = {
                before: -this.windowHeight,
                current: 0,
                next: this.windowHeight
              }
              this.nowTransition = {
                self: this.rebackTime,
                others: 0
              }
              setTimeout(() => {
                this.nowTransition = {
                  self: 0,
                  others: 0
                }
                this.canmove = true;
              }, this.rebackTime * 1000)


            }
          } else {
            this.nowTop = {
              before: -this.windowHeight,
              current: 0,
              next: this.windowHeight
            }
          }
        }
      },
      async fetch() {
        if (this.needFetch) {
          if (JSON.stringify(this.app.$route.params) == "{}") {

          } else {
            this.enterParams = this.app.$route.params
            this.list = this.enterParams.list
            this.index = this.enterParams.index
            this.hasNext = this.enterParams.hasNext
            this.start = this.enterParams.list[this.enterParams.list.length - 1].id
            this.selectedPlatform = this.enterParams.selectedPlatform
            this.selectedCategory = this.enterParams.selectedCategory
          }
          this.preFetchFinished = true
          // var idlist = [];
          // for (var i = 0;i<this.list.length;i++) {
          //   idlist.push(this.list[i].id)
          // }
          // this.getSaleCollectedList(idlist.join(","))
        }

        this.pullupTime = 0.3
        this.rebackTime = 0.2
        this.windowHeight = window.innerHeight
        this.nowTop = {
          before: -this.windowHeight,
          current: 0,
          next: this.windowHeight
        }
        this.nowTransition = {
          self: 0,
          others: 0
        }
        this.touchStart = 0
        this.canmove = true
        this.hasStart = true
      },
      canRequest() {
        if (this.list.length - this.index <= this.preloadLength && this.preFetchFinished) {
          this.preFetchFinished = false
          if (this.hasNext) {
            // setTimeout( () => {this.fetchSaleList(false,this.start)},18000);
            this.fetchSaleList(false, this.start)
          } else {
            if (this.index + 1 == this.list.length) {
              utils.toast("已经是最后一条信息啦")
            }
          }
        }
      },
      fetchSaleList(isShowLoading, start) {
        var that = this
        var params = {}
        params.start = start
        params.platform = this.selectedPlatform.id
        params.category = this.selectedCategory.id

        httputil.request("discounts", params, function (successresult) {
          that.preFetchFinished = true
          if (start == "") {
            that.list = [];
          }
          that.hasNext = successresult.discount_list.has_next
          if (successresult.discount_list.discounts.length != 0) {
            that.start = successresult.discount_list.discounts[successresult.discount_list.discounts.length - 1].id
            if (start == "") {
              that.list = successresult.discount_list.discounts;
              that.canRequest();
            } else {
              that.list = that.list.concat(successresult.discount_list.discounts);
            }


            // var idlist = [];
            // for (var i = 0;i<successresult.discounts.length;i++) {
            //   idlist.push(successresult.discounts[i].id)
            // }
            // that.getSaleCollectedList(idlist.join(","))
          }
        }, function (errorresult) {
          that.preFetchFinished = true
        }, "GET", isShowLoading)
      },
      getSaleCollectedList(ids) {
        var that = this
        var params = {ids: ids}
        httputil.request("collect/discount", params, function (successresult) {
          for (var i = 0; i < successresult.collects.length; i++) {
            for (var j = 0; j < that.list.length; j++) {
              if (successresult.collects[i].id == that.list[j].id) {
                Vue.set(that.list[j], 'collected', successresult.collects[i].collected)
                // that.list[j].collected = successresult.collects[i].collected
              }
            }
          }
          that.nowTop = {
            before: -that.windowHeight,
            current: 0,
            next: that.windowHeight,
          }

        }, function (errorresult) {

        }, "GET", false)
      },
      collect(sale) {
        var that = this
        if (this.app.$getLoginStatus()) {
          sale.collected == 0 ? sale.collected = 1 : sale.collected = 0
          that.nowTop = {
            before: -that.windowHeight,
            current: 0,
            next: that.windowHeight,
          }
        }
        var params = {discount_id: sale.id}
        httputil.request("collect/discount", params, function (successresult) {
          for (var j = 0; j < that.list.length; j++) {
            if (sale.id == that.list[j].id) {
              Vue.set(that.list[j], 'collected', successresult.collected)
              // that.list[j].collected = successresult.collected
            }
          }
          that.nowTop = {
            before: -that.windowHeight,
            current: 0,
            next: that.windowHeight,
          }
        }, function (errorresult) {

        }, "POST", false, "salelist")
      },
      skip(sale) {
        this.needFetch = false
        this.preFetchFinished = true
        if (window.location.href.indexOf(this.app.GLOBAL.skitToThirdWebSign) == -1) {
          window.location.replace(window.location.href + this.app.GLOBAL.skitToThirdWebSign)
        }
        window.location.href = sale.link;
      },
    },
    collectsalelist: {
      data() {
        return {
          list: [],
          has_next: true,
          discount_id: "",
          collect_time: "",
          current_length: 0,
          needFetch: true,
        }
      },
      // route: {
      //   once: false // 当前页面，只加载一次，这样我们就可以做上拉加载了
      // },
      fetch() {
        if (this.needFetch) {
          var that = this
          this.list = []
          this.has_next = true
          this.discount_id = ""
          this.collect_time = ""
          this.current_length = 0
        }
      },
    },
    collectsalefullscreenlist: {
      data() {
        return {
          windowHeight: 1,
          index: 0,
          distance: 0,//手指在页面滑动的距离
          nowTop: {
            before: -this.windowHeight,
            current: 0,
            next: this.windowHeight
          },
          nowTransition: {
            self: 0,
            others: 0
          },

          touchStart: 0,
          canmove: true,
          hasStart: true,
          pullupTime: 0.3,
          rebackTime: 0.2,
          list: [],
          hasNext: true,
          discount_id: "",
          collect_time: "",
          preloadLength: 10,
          enterParams: "",
          preFetchFinished: true,

          needFetch: true
        }
      },

      top(i) {
        var topValue = 0;
        if (i == this.index) {
          topValue = this.nowTop.current;
        } else if (i == this.index - 1) {
          topValue = this.nowTop.before;
        } else if (i == this.index + 1) {
          topValue = this.nowTop.next
        } else {
          topValue = (i - this.index) * this.windowHeight
        }
        return topValue + 'px'
      },
      transition(i) {
        var transitionVal = 0;
        if (i == this.index - 1 || i == this.index || i == this.index + 1) {
          transitionVal = this.nowTransition.self
        } else {
          transitionVal = this.nowTransition.others
        }
        return transitionVal
      },

      panStart(e) {
        e.preventDefault();
        this.hasStart = true;
        if (!this.canmove) {
          this.hasStart = false;
          return false
        }
        this.distance = 0;
        this.nowTop = {
          before: -this.windowHeight,
          current: 0,
          next: this.windowHeight,
        }
        this.nowTransition = {
          self: 0,
          others: 0
        }
        this.touchStart = e.center.y;

      },
      panMove(e) {
        e.preventDefault();
        if (this.hasStart) {
          if (!this.canmove && this.touchStart == 0) {
            return false
          } else {
            this.distance = e.center.y - this.touchStart;
            //第一页不能下滑翻页，最后一页不能上滑翻页

            if (!((this.index == 0 && this.distance > 0) || ((this.index == this.list.length - 1) && this.distance < 0))) {
              this.nowTop = {
                before: -this.windowHeight + this.distance,
                current: this.distance,
                next: this.windowHeight + this.distance,
              }
            } else {

            }
          }
        }


      },
      panEnd(e) {
        e.preventDefault();
        if (this.hasStart) {
          if (!this.canmove || this.touchStart == 0) {
            return
          }
          if (!((this.index == 0 && this.distance > 0) || (this.index == this.list.length - 1 && this.distance < 0))) {
            this.touchStart = 0;

            if (this.distance > 0 && this.distance > this.windowHeight / 10) {//可以下滑
              this.distance = 0;
              this.canmove = false;
              this.nowTop = {
                before: 0,
                current: this.windowHeight,
                next: 2 * this.windowHeight
              }
              this.nowTransition = {
                self: this.pullupTime,
                others: 0
              }
              setTimeout(() => {
                this.nowTop = {
                  before: -this.windowHeight,
                  current: 0,
                  next: this.windowHeight,
                  others: 0
                }
                this.nowTransition = {
                  self: 0,
                  others: 0
                }
                this.index--;
                // this.canRequest()
                this.canmove = true;

              }, this.pullupTime * 1000)
//            $(this.$refs[`touch${this.index}`][0]).addClass('animated').siblings().removeClass('animated');
//            var obj = {
//              hasAnimats:true,
//              name:`touch${this.index-1}`
//            }
//            this.$store.commit('showAnimation',obj)

            } else if (this.distance > 0 && this.distance < this.windowHeight / 10) {//不可以下滑
              this.distance = 0;
              this.canmove = false;
              this.nowTop = {
                before: -this.windowHeight,
                current: 0,
                next: this.windowHeight
              }
              this.nowTransition = {
                self: this.rebackTime,
                others: 0
              }
              setTimeout(() => {
                this.nowTransition = {
                  self: 0,
                  others: 0
                }
                this.canmove = true
              }, this.rebackTime * 1000)

            } else if (this.distance < 0 && this.distance * (-1) > this.windowHeight / 10) {//可以上滑
              this.distance = 0;
              this.canmove = false;
              this.nowTop = {
                before: -2 * this.windowHeight,
                current: -this.windowHeight,
                next: 0
              }
              this.nowTransition = {
                self: this.pullupTime,
                others: 0
              }
              setTimeout(() => {
                this.nowTop = {
                  before: -this.windowHeight,
                  current: 0,
                  next: this.windowHeight
                }
                this.nowTransition = {
                  self: 0,
                  others: 0
                }
                this.index++;
                this.canRequest()
                this.canmove = true;
                // this.reportReadSale();
              }, this.pullupTime * 1000)
//            $(this.$refs[`touch${this.index}`][0]).addClass('animated').siblings().removeClass('animated');
//            var obj = {
//              hasAnimats:true,
//              name:`touch${this.index+1}`
//            }
//            this.$store.commit('showAnimation',obj)
            } else if (this.distance < 0 && this.distance * (-1) < this.windowHeight / 10) {//不可以上滑
              this.distance = 0;
              this.canmove = false;
              this.nowTop = {
                before: -this.windowHeight,
                current: 0,
                next: this.windowHeight
              }
              this.nowTransition = {
                self: this.rebackTime,
                others: 0
              }
              setTimeout(() => {
                this.nowTransition = {
                  self: 0,
                  others: 0
                }
                this.canmove = true;
              }, this.rebackTime * 1000)


            }
          } else {
            this.nowTop = {
              before: -this.windowHeight,
              current: 0,
              next: this.windowHeight
            }
          }
        }
      },
      async fetch() {
        if (this.needFetch) {
          if (JSON.stringify(this.app.$route.params) == "{}") {
            // this.enterParams =  JSON.parse(localStorage.getItem("collectsalefullscreenlist"))
          } else {
            this.enterParams = this.app.$route.params
            this.list = this.enterParams.list
            this.index = this.enterParams.index
            this.hasNext = this.enterParams.hasNext
            this.discount_id = this.enterParams.list[this.enterParams.list.length - 1].id
            this.collect_time = this.enterParams.list[this.enterParams.list.length - 1].collect_time
          }
          this.preFetchFinished = true

          // var idlist = [];
          // for (var i = 0;i<this.list.length;i++) {
          //   idlist.push(this.list[i].id)
          // }
          // this.getSaleCollectedList(idlist.join(","))
        }

        this.pullupTime = 0.3
        this.rebackTime = 0.2
        this.windowHeight = window.innerHeight
        this.nowTop = {
          before: -this.windowHeight,
          current: 0,
          next: this.windowHeight
        }
        this.nowTransition = {
          self: 0,
          others: 0
        }
        this.touchStart = 0
        this.canmove = true
        this.hasStart = true
      },
      canRequest() {
        if (this.list.length - this.index <= this.preloadLength && this.preFetchFinished) {
          this.preFetchFinished = false
          if (this.hasNext) {
            this.fetchSaleList(false, this.discount_id, this.collect_time)
          } else {
            if (this.index + 1 == this.list.length) {
              utils.toast("已经是最后一条信息啦")
            }
          }
        }
      },
      fetchSaleList(isShowLoading, discount_id, collect_time) {
        var that = this
        var params = {}
        params.discount_id = discount_id
        params.collect_time = collect_time
        httputil.request("collect/discounts", params, function (successresult) {
          that.preFetchFinished = true
          if (discount_id == "" && collect_time == "") {
            that.list = [];
          }
          that.hasNext = successresult.collect_list.has_next
          if (successresult.collect_list.discounts.length != 0) {
            that.discount_id = successresult.collect_list.discounts[successresult.collect_list.discounts.length - 1].id
            that.collect_time = successresult.collect_list.discounts[successresult.collect_list.discounts.length - 1].collect_time
            if (discount_id == "" && collect_time == "") {
              that.list = successresult.collect_list.discounts;
              that.canRequest();
            } else {
              that.list = that.list.concat(successresult.collect_list.discounts);
            }


            // var idlist = [];
            // for (var i = 0;i<successresult.collect_list.discounts.length;i++) {
            //   idlist.push(successresult.collect_list.discounts[i].id)
            // }
            // that.getSaleCollectedList(idlist.join(","))
          }
        }, function (errorresult) {
          that.preFetchFinished = true
        }, "GET", isShowLoading)
      },
      getSaleCollectedList(ids) {
        var that = this
        var params = {ids: ids}
        httputil.request("collect/discount", params, function (successresult) {
          for (var i = 0; i < successresult.collects.length; i++) {
            for (var j = 0; j < that.list.length; j++) {
              if (successresult.collects[i].id == that.list[j].id) {
                Vue.set(that.list[j], 'collected', successresult.collects[i].collected)
                // that.list[j].collected = successresult.collects[i].collected
              }
            }
          }
          that.nowTop = {
            before: -that.windowHeight,
            current: 0,
            next: that.windowHeight,
          }

        }, function (errorresult) {

        }, "GET", false)
      },
      collect(sale) {
        var that = this
        if (this.app.$getLoginStatus()) {
          sale.collected == 0 ? sale.collected = 1 : sale.collected = 0
          that.nowTop = {
            before: -that.windowHeight,
            current: 0,
            next: that.windowHeight,
          }
        }
        var params = {discount_id: sale.id}
        httputil.request("collect/discount", params, function (successresult) {
          for (var j = 0; j < that.list.length; j++) {
            if (sale.id == that.list[j].id) {
              Vue.set(that.list[j], 'collected', successresult.collected)
              // that.list[j].collected = successresult.collected
            }
          }
          that.nowTop = {
            before: -that.windowHeight,
            current: 0,
            next: that.windowHeight,
          }
        }, function (errorresult) {

        }, "POST", false, "collectsalefullscreenlist")
      },
      skip(sale) {
        this.needFetch = false
        this.preFetchFinished = true
        if (window.location.href.indexOf(this.app.GLOBAL.skitToThirdWebSign) == -1) {
          window.location.replace(window.location.href + this.app.GLOBAL.skitToThirdWebSign)
        }
        window.location.href = sale.link;
      }
    },

    articlechannel: {
      data() {
        return {
          channel_id: 0,
          needFetch: true,
          showview: false,
          start: 0,
          has_next: true,
          list: [],
          headbanner: {},
        }
      },
      // route: {
      //   once: true // 当前页面，只加载一次，这样我们就可以做上拉加载了
      // },
      skipToArticle(id) {
        this.needFetch = false
        this.app.$router.push({name: 'contentdetail', query: {id: id}})
        // setTimeout(() => {
        //   this.app.$router.push({ name: 'contentdetail', query: {id:id}})
        // }, 1)

      },
      fetchSaleList(type, isShowLoading, requestStart, done) {
        var that = this
        var params = {};
        params.start = requestStart
        params.channel_id = this.channel_id
        httputil.request("channel/articles", params, function (successresult) {
          that.showview = true
          that.has_next = successresult.article_list.has_next == 0 ? false : true;
          if (type == "down" || type == "up") {
            done();
          }
          if (requestStart == 0) {
            that.vuet.store.articlechannel.$scroll.content.y = 0
            that.list = successresult.article_list.articles;
            // that.headbanner = successresult.channel
          } else {
            that.list = that.list.concat(successresult.article_list.articles);
          }
          if (successresult.article_list.articles.length != 0) {
            that.start = that.list[that.list.length - 1].id
            // that.current_length = successresult.article_list.articles.length
          } else {

          }

        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      async fetch() {
        this.channel_id = this.app.$route.query.id
        if (this.needFetch) {
          this.onInit()
        }
      },
      onRefresh(done) {
        this.start = 0
        this.fetchSaleList("down", false, this.start, done)
      },
      onGetmore(done) {
        if (this.has_next) {
          this.fetchSaleList("up", false, this.start, done)
        }
      },
      onInit() {
        this.start = 0
        this.list = []
        this.headbanner = {}
        this.showview = false
        this.has_next = true;
        this.fetchSaleList("init", true, this.start)
      },
    },
    articlezcchannel: {
      data() {
        return {
          channel_id: 0,
          cat_id: 0,
          needFetch: true,
          showview: false,
          start: 0,
          has_next: true,
          list: [],
          topcategory: [{name: "全部", id: 0, checked: true}],
          headbanner: {},
        }
      },
      // route: {
      //   once: true // 当前页面，只加载一次，这样我们就可以做上拉加载了
      // },
      skipToArticle(id) {
        this.needFetch = false
        this.app.$router.push({name: 'contentdetail', query: {id: id}})

      },
      changeCategory(selectedCategory, index) {
        var changed = this.topcategory
        for (var i = 0; i < changed.length; i++) {
          if (i == index) {
            changed[i].checked = true
          } else {
            changed[i].checked = false
          }
        }
        this.start = 0
        this.cat_id = selectedCategory.id
        // this.list = []
        // this.showview = false
        this.fetchSaleList("", true, this.start)
      },
      fetchSaleList(type, isShowLoading, requestStart, done) {
        var that = this
        var params = {};
        params.start = requestStart
        params.channel_id = this.channel_id
        params.cat_id = this.cat_id
        httputil.request("channel/articles", params, function (successresult) {
          that.showview = true
          that.has_next = successresult.article_list.has_next == 0 ? false : true;
          if (type == "down" || type == "up") {
            done();
          }
          if (type == "init") {
            that.topcategory = that.topcategory.concat(successresult.categories)
          }
          if (requestStart == 0) {
            that.vuet.store.articlezcchannel.$scroll.content.y = 0
            that.list = successresult.article_list.articles;
            that.headbanner = successresult.channel
          } else {
            that.list = that.list.concat(successresult.article_list.articles);
          }
          if (successresult.article_list.articles.length != 0) {
            that.start = that.list[that.list.length - 1].id
            that.current_length = successresult.article_list.articles.length
          } else {

          }

        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      async fetch() {
        this.channel_id = this.app.$route.query.id
        if (this.needFetch) {
          this.onInit()
        }
      },
      onRefresh(done) {
        this.start = 0
        this.fetchSaleList("down", false, this.start, done)
      },
      onGetmore(done) {
        if (this.has_next) {
          this.fetchSaleList("up", false, this.start, done)
        }
      },
      onInit() {
        this.start = 0
        this.topcategory = [{name: "全部", id: 0, checked: true}]
        this.cat_id = 0
        this.list = []
        this.showview = false
        this.fetchSaleList("init", true, this.start)
      },
    },
    resoulist: {
      data() {
        return {
          needFetch: true,
          showview: false,
          start: 0,
          has_next: true,
          list: [],
          size: 6
        }
      },
      // route: {
      //   once: true // 当前页面，只加载一次，这样我们就可以做上拉加载了
      // },
      skipToArticle(id) {
        this.needFetch = false
        this.app.$router.push({name: 'contentdetail', query: {id: id}})
      },
      fetchSaleList(type, isShowLoading, requestStart, done) {
        var that = this
        var params = {size: 60};
        params.start = requestStart
        httputil.request("hot/search", params, function (successresult) {
          that.showview = true
          that.has_next = successresult.has_next == 0 ? false : true;
          if (type == "down" || type == "up") {
            done();
          }
          if (requestStart == 0) {
            that.vuet.store.resoulist.$scroll.content.y = 0
            that.list = successresult.searches;
          } else {
            that.list = that.list.concat(successresult.searches);
          }
          if (successresult.searches.length != 0) {
            that.start = that.list[that.list.length - 1].sort
          } else {

          }

        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      async fetch() {
        if (this.needFetch) {
          this.onInit()
        }
      },
      onRefresh(done) {
        this.start = 0
        this.fetchSaleList("down", false, this.start, done)
      },
      onGetmore(done) {
        if (this.has_next) {
          this.fetchSaleList("up", false, this.start, done)
        }
      },
      onInit() {
        this.start = 0
        this.fetchSaleList("init", true, this.start)
      },
    },
    contentdetail: {
      data() {
        return {
          windowHeight: 1,
          id: 0,
          detail: {},
          needFetch: true,
          commentlist: []
        }
      },

      async fetch() {
        if (this.needFetch) {
          var that = this
          this.windowHeight = window.innerHeight
          this.detail = {}
          this.commentlist = []
          this.id = this.app.$route.query.id
          var params = {id: this.id}
          httputil.request("article/detail/h5", params, function (successresult) {
            that.detail = successresult.article

            that.getCommentList();
          }, function (errorresult) {

          }, "GET", true)

        }
      },
      submitComment() {
        var that = this
        var params = {article_id: that.detail.id, content: "这是我的评论！" + new Date().toLocaleTimeString()}
        httputil.request("article/comment", params, function (successresult) {

        }, function (errorresult) {

        }, "POST", true, "contentdetail")
      },
      getCommentList() {
        var that = this
        var params = {article_id: that.id}
        httputil.request("article/comments", params, function (successresult) {
          that.commentlist = successresult.comment_list.comments
        }, function (errorresult) {

        }, "GET", true, "contentdetail")
      },
      collect() {
        var that = this
        if (this.app.$getLoginStatus()) {
          if (this.detail.collected == 0) {
            this.detail.collected = 1
            this.detail.collects_total = this.detail.collects_total + 1
          } else {
            this.detail.collected = 0
            this.detail.collects_total = this.detail.collects_total - 1
          }
          // this.detail.collected == 0 ? this.detail.collected = 1 : this.detail.collected = 0
        }
        var params = {id: this.detail.id}
        httputil.request("collect/article", params, function (successresult) {
          that.detail.collected = successresult.collected
        }, function (errorresult) {

        }, "POST", false, "contentdetail")
      },
      like() {
        var that = this
        if (this.app.$getLoginStatus()) {
          if (this.detail.liked == 0) {
            this.detail.liked = 1
            this.detail.likes_total = this.detail.likes_total + 1
          } else {
            this.detail.liked = 0
            this.detail.likes_total = this.detail.likes_total - 1
          }
        }
        var params = {id: this.detail.id}
        httputil.request("like/article", params, function (successresult) {
          that.detail.liked = successresult.liked
        }, function (errorresult) {

        }, "POST", false, "contentdetail")
      },
      commentlike(item) {
        var that = this
        if (this.app.$getLoginStatus()) {
          if (item.liked == 0) {
            item.liked = 1
            item.likes_total = item.likes_total + 1
          } else {
            item.liked = 0
            item.likes_total = item.likes_total - 1
          }
        }
        var params = {comment_id: item.id}
        httputil.request("like/article-comment", params, function (successresult) {
          item.liked = successresult.liked
        }, function (errorresult) {

        }, "POST", false, "contentdetail")
      },

      skipToDownload() {
        this.needFetch = false
        this.app.$router.push({name: 'downloadpage'})
      },
      skipToUserpage(id) {
        this.needFetch = false
        this.app.$router.push({name: 'userpage', query: {id: id}})
      },
      skip(sale) {
        // this.needFetch = false
        window.location.href = sale.link;
      }
    },
    goodsdetail: {
      data() {
        return {
          id: 0,
          detail: {},
          selected_spec: {},
          needFetch: true,
        }
      },

      async fetch() {
        if (this.needFetch) {
          var that = this
          this.detail = {}
          this.id = this.app.$route.query.id
          var params = {id: this.id}
          httputil.request("goods/detail", params, function (successresult) {
            that.detail = successresult.goods
            that.selected_spec = that.detail.products[0]
          }, function (errorresult) {

          }, "GET", true)

        }
      },
      skipToOrder() {
        if (this.app.$getLoginStatus()) {
          this.needFetch = false
          this.app.$router.push({
            name: 'orderconfirm',
            query: {goods_id: this.detail.id, product_id: this.selected_spec.id}
          })
        } else {
          this.app.$pushRouteByJson({name: "login"})
        }

      },
      collect() {
        var that = this
        if (this.app.$getLoginStatus()) {
          if (this.detail.collected == 0) {
            this.detail.collected = 1
            this.detail.collects_total = this.detail.collects_total + 1
          } else {
            this.detail.collected = 0
            this.detail.collects_total = this.detail.collects_total - 1
          }
          // this.detail.collected == 0 ? this.detail.collected = 1 : this.detail.collected = 0
        }
        var params = {id: this.detail.id}
        httputil.request("collect/goods", params, function (successresult) {
          that.detail.collected = successresult.collected
        }, function (errorresult) {

        }, "POST", false, "goodsdetail")
      },

      skip(sale) {
        // this.needFetch = false
        window.location.href = sale.link;
      }
    },
    goodscollects: {
      data() {
        return {
          needFetch: true,
          showview: false,
          start: 0,
          time: 0,
          has_next: true,
          list: [],
        }
      },
      skipToGoodsDetail(item) {
        this.needFetch = false
        this.app.$router.push({name: 'goodsdetail', query: {id: item.id}})
      },
      fetchList(type, isShowLoading, done) {
        var that = this
        var params = {};
        params.id = this.start
        params.start = this.time
        httputil.request("collect/goods", params, function (successresult) {
          that.showview = true
          that.has_next = successresult.goods_list.has_next == 0 ? false : true;
          if (type == "down" || type == "up") {
            done();
          }
          if (that.start == 0) {
            that.vuet.store.goodscollects.$scroll.content.y = 0
            that.list = successresult.goods_list.goods;
          } else {
            that.list = that.list.concat(successresult.goods_list.goods);
          }
          if (successresult.goods_list.goods.length != 0) {
            that.start = that.list[that.list.length - 1].id
            that.time = that.list[that.list.length - 1].collected_time
          } else {

          }

        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      async fetch() {
        if (this.needFetch) {
          this.list = []
          this.showview = false
          this.start = 0
          this.time = 0
          this.has_next = true
          this.fetchList("", true)
        }
      },
      onRefresh(done) {
        this.start = 0
        this.time = 0
        this.fetchList("down", false, done)
      },
      onGetmore(done) {
        if (this.has_next) {
          this.fetchList("up", false, done)
        }
      },
    },
    orderconfirm: {
      data() {
        return {
          windowHeight: 1,
          goods_id: 0,
          product_id: 0,
          detail: {},
          needFetch: true,
          openid: "",
          redirecturi: ""
        }
      },
      wxlogin(code) {
        var that = this
        var params = {code: code}
        httputil.request("wechat/openid", params, function (successresult) {
          that.openid = successresult.openid
        }, function () {

        }, "POST", true)
      },
      async fetch() {
        var that = this
        if (this.needFetch) {
          if (window.location.search.lastIndexOf('code=') !== -1) {
            this.wxlogin(window.location.search.substring(window.location.search.lastIndexOf('code=') + 5, window.location.search.lastIndexOf('&')))
          } else {
            httputil.request("wechat/openid", {redirect_uri: window.location.href}, function (successresult) {
              that.app.$BackRoute(-1)
              setTimeout(() => {
                window.location.href = successresult.redirect_uri
              }, 10)


            }, function () {

            }, "GET", true)
          }
        }
        this.windowHeight = window.innerHeight
        this.goods_id = this.app.$route.query.goods_id
        this.product_id = this.app.$route.query.product_id
        var params = {goods_id: this.goods_id, product_id: this.product_id}
        httputil.request("goods/buy", params, function (successresult) {
          that.detail = successresult
        }, function (errorresult) {

        }, "POST", true)

      },
      submit() {
        var that = this

        var params = {
          pay_code: "weixin_pay",
          goods_id: this.goods_id,
          product_id: this.product_id,
          address_id: this.detail.address.id,
          openid: this.openid
        }
        httputil.request("order/create", params, function (successresult) {
          var result = successresult.payment.weixin_pay
          that.getWeixinPay(result)
        }, function (errorresult) {

        }, "POST", true)
      },
      getWeixinPay(data) {
        var vm = this;
        if (typeof WeixinJSBridge == "undefined") {//微信浏览器内置对象。参考微信官方文档
          if (document.addEventListener) {
            document.addEventListener('WeixinJSBridgeReady', vm.onBridgeReady(data), false);
          } else if (document.attachEvent) {
            document.attachEvent('WeixinJSBridgeReady', vm.onBridgeReady(data));
            document.attachEvent('onWeixinJSBridgeReady', vm.onBridgeReady(data));
          }
        } else {
          vm.onBridgeReady(data);
        }
      },
      /**
       * @method 支付费用方法
       * @param data:后台返回的支付对象,(详情微信公众号支付API中H5提交支付);
       */
      onBridgeReady: function (data) {
        var vm = this;
        WeixinJSBridge.invoke(
          'getBrandWCPayRequest', data,
          function (res) {
            // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
            if (res.err_msg == "get_brand_wcpay_request：ok") {
              // window.location.href =
              window.location.href = "/"
            } else {
              window.location.href = "/"
            }
          }
        );
      },
      collect(sale) {
        var that = this
        if (this.app.$getLoginStatus()) {
          sale.collected == 0 ? sale.collected = 1 : sale.collected = 0
        }
        var params = {discount_id: sale.id}
        httputil.request("collect/discount", params, function (successresult) {
          sale.collected = successresult.collected
        }, function (errorresult) {

        }, "POST", false, "saledetail")
      },
      skip(sale) {
        // this.needFetch = false
        if (window.location.href.indexOf(this.app.GLOBAL.skitToThirdWebSign) == -1) {
          window.location.replace(window.location.href + this.app.GLOBAL.skitToThirdWebSign)
        }
        window.location.href = sale.link;
      }
    },
    orderlist: {
      data() {
        return {
          needFetch: true,
          showview: false,
          apiname: "my/orders",
          start: 0,
          has_next: true,
          list: [],
          topcategory: [{name: "全部", id: 0, checked: true}, {name: "待付款", id: 1}, {name: "待收货", id: 2}, {
            name: "已完成",
            id: 3
          }, {name: "已取消", id: 4}],
        }
      },
      skipToDetail(id) {
        this.needFetch = false
        this.app.$router.push({name: 'orderdetail', query: {id: id}})

      },
      changeCategory(id) {
        var changed = this.topcategory
        for (var i = 0; i < changed.length; i++) {
          if (i == id) {
            changed[i].checked = true
          } else {
            changed[i].checked = false
          }
        }
        this.start = 0
        if (id == 0) {
          this.apiname = "my/orders"
        } else if (id == 1) {
          this.apiname = "my/orders/un_pay"
        } else if (id == 2) {
          this.apiname = "my/orders/wait_receive"
        } else if (id == 3) {
          this.apiname = "my/orders/completed"
        } else if (id == 4) {
          this.apiname = "my/orders/canceled"
        }
        this.fetchList("", true)
      },
      fetchList(type, isShowLoading, done) {
        var that = this
        var params = {};
        params.start = this.start
        httputil.request(this.apiname, params, function (successresult) {
          that.showview = true
          that.has_next = successresult.order_list.has_next == 0 ? false : true;
          if (type == "down" || type == "up") {
            done();
          }
          if (that.start == 0) {
            that.vuet.store.orderlist.$scroll.content.y = 0
            that.list = successresult.order_list.orders;
          } else {
            that.list = that.list.concat(successresult.order_list.orders);
          }
          if (successresult.order_list.orders.length != 0) {
            that.start = that.list[that.list.length - 1].id

          } else {

          }

        }, function (errorresult) {
          if (type == "down" || type == "up") {
            done();
          }

        }, "GET", isShowLoading)
      },
      async fetch() {
        if (this.needFetch) {
          this.changeCategory(this.app.$route.query.id)
          this.list = []
          this.showview = false
        }
      },
      onRefresh(done) {
        this.start = 0
        this.fetchList("down", false, done)
      },
      onGetmore(done) {
        if (this.has_next) {
          this.fetchList("up", false, done)
        }
      },
    },
    orderdetail: {
      data() {
        return {
          id: 0,
          detail: {},
          countdown: 0,
          needFetch: true,
          redirect_uri: ""
        }
      },
      countdowntime() {
        var that = this;
        that.countdown = that.detail.expires_in
        var timer = setInterval(function () {
          that.countdown = that.countdown - 1;
          if (that.countdown == 0) {
            that.fetch()
            clearInterval(timer);
          }
        }, 1000);
      },
      ConfirmOrder() {
        var that = this
        var params = {id: this.id}
        httputil.request("order/receipted", params, function (successresult) {
          that.fetch()
        }, function (errorresult) {

        }, "POST", true)
      },
      cancelOrder() {
        var that = this
        var params = {id: this.id}
        httputil.request("order/cancel", params, function (successresult) {
          that.fetch()
        }, function (errorresult) {

        }, "POST", true)
      },
      pay() {
        window.location.href = this.redirect_uri;
      },
      wxlogin(code) {
        var that = this
        var params = {code: code}
        httputil.request("wechat/openid", params, function (successresult) {
          that.submitPay(successresult.openid)
        }, function () {

        }, "POST", true)
      },
      submitPay(openid) {
        var that = this
        var params = {pay_code: "weixin_pay", id: this.id, openid: openid}
        httputil.request("order/pay", params, function (successresult) {
          var result = successresult.payment.weixin_pay
          that.getWeixinPay(result)
        }, function () {

        }, "POST", true)
      },

      getWeixinPay(data) {
        var vm = this;
        if (typeof WeixinJSBridge == "undefined") {//微信浏览器内置对象。参考微信官方文档
          if (document.addEventListener) {
            document.addEventListener('WeixinJSBridgeReady', vm.onBridgeReady(data), false);
          } else if (document.attachEvent) {
            document.attachEvent('WeixinJSBridgeReady', vm.onBridgeReady(data));
            document.attachEvent('onWeixinJSBridgeReady', vm.onBridgeReady(data));
          }
        } else {
          vm.onBridgeReady(data);
        }
      },
      onBridgeReady: function (data) {
        var vm = this;
        WeixinJSBridge.invoke(
          'getBrandWCPayRequest', data,
          function (res) {
            // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
            if (res.err_msg == "get_brand_wcpay_request：ok") {
              // window.location.href =
              window.location.href = "/"
            } else {
              window.location.href = "/"
            }
          }
        );
      },

      async fetch() {
        if (this.needFetch) {
          var that = this
          this.detail = {}
          this.id = this.app.$route.query.id
          var params = {id: this.id}
          httputil.request("order/detail", params, function (successresult) {
            that.detail = successresult.order
            if (that.detail.status == 0) {
              that.countdowntime();
            }
          }, function (errorresult) {

          }, "GET", true)

          if (window.location.search.lastIndexOf('code=') !== -1) {
            this.wxlogin(window.location.search.substring(window.location.search.lastIndexOf('code=') + 5, window.location.search.lastIndexOf('&')))
          } else {
            httputil.request("wechat/openid", {redirect_uri: window.location.href}, function (successresult) {
              that.redirect_uri = successresult.redirect_uri
            }, function () {

            }, "GET", false)
          }
        }
      },
    },
    addresslist: {
      data() {
        return {
          list: [],
        }
      },
      deleteaddress(item) {
        var that = this
        var params = {id: item.id};
        httputil.request("address", params, function (successresult) {
          that.fetchList();

        }, function (errorresult) {

        }, "DELETE", true)
      },
      fetchList() {
        var that = this
        var params = {};
        httputil.request("address/list", params, function (successresult) {
          that.list = successresult.address_list;

        }, function (errorresult) {

        }, "GET", true)
      },
      async fetch() {
        this.fetchList();
      },
    },
    newaddress: {
      data() {
        return {
          list: [],
          inputname: "",
          inputmobile: "",
          inputdetailaddress: "",
          provincelist: [],
          provinceitem: 0,
          selectedProvince: {},
          citylist: [],
          cityitem: 0,
          selectedCity: {},
          districtlist: [],
          districtitem: 0,
          selectedDistrict: {},
        }
      },
      // route: {
      //   once: true // 当前页面，只加载一次，这样我们就可以做上拉加载了
      // },
      skipToArticle(id) {
        // this.needFetch = false
        // this.app.$router.push({name: 'contentdetail', query: {id: id}})


      },
      checkmobilestatus() {
        if (this.inputmobile.length > 11) {
          utils.toast("手机号不能超过11位哦")
          this.inputmobile = this.inputmobile.slice(0, 11)
        }
      },
      submit() {
        var that = this
        if (JSON.stringify(that.selectedProvince) != '{}') {
          httputil.request("address/create", {
            province_id: that.selectedProvince.id,
            city_id: that.selectedCity.id,
            town_id: that.selectedDistrict.id,
            mobile: that.inputmobile,
            name: that.inputname,
            address: that.inputdetailaddress
          }, function (successresult) {
            that.app.$BackRoute(-1)
          }, function (errorresult) {

          }, "POST", true)
        } else {
          utils.toast("请选择省市区")
        }

      },
      fetchList() {
        var that = this
        var params = {};
        httputil.request("city", params, function (successresult) {
          that.list = successresult.city_list;
          // that.provincelist = that.list.filter(
          //   function(x) {
          //   return x.parent_id == 0}
          //   )
          // that.provinceitem = 0
          // that.citylist = that.list.filter(
          //   function(x) {
          //     return x.parent_id == that.provincelist[that.provinceitem].id}
          // )
          // that.cityitem = 0
          // that.districtlist = that.list.filter(
          //   function(x) {
          //     return x.parent_id == that.citylist[that.cityitem].id}
          // )
          // that.districtitem = 0
        }, function (errorresult) {

        }, "GET", true)
      },
      async fetch() {
        this.fetchList();
      },
    },

    notedetail: {
      data() {
        return {
          windowHeight: 1,
          id: 0,
          detail: {},
          needFetch: true,
          commentlist: []
        }
      },

      async fetch() {
        if (this.needFetch) {
          var that = this
          this.windowHeight = window.innerHeight
          this.detail = {}
          this.commentlist = []
          this.id = this.app.$route.query.id
          var params = {id: this.id}
          httputil.request("note/detail", params, function (successresult) {
            that.detail = successresult.note
            httputil.request("wechat/jsapi", {url:window.location.href}, function (successresult) {
              wx.config({
                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                appId: successresult.config.appId, // 必填，公众号的唯一标识
                timestamp: successresult.config.timestamp, // 必填，生成签名的时间戳
                nonceStr: successresult.config.nonceStr, // 必填，生成签名的随机串
                signature: successresult.config.signature,// 必填，签名，见附录1
                jsApiList: ["updateAppMessageShareData","updateTimelineShareData","chooseWXPay"] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
              });
              wx.ready(function(){
                wx.updateAppMessageShareData({
                  title: that.detail.title == '' ? '我在妙汇发现了一篇笔记' : that.detail.title, // 分享标题
                  desc: that.detail.content == '' ? '快来看一下吧！' : that.detail.content, // 分享描述
                  link: window.location.href, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                  imgUrl: that.detail.cover_url, // 分享图标
                  success: function () {

                  }
                })
                  wx.updateTimelineShareData({
                    title: that.detail.title == '' ? '我在妙汇发现了一篇笔记' : that.detail.title, // 分享标题
                    link: window.location.href, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                    imgUrl: that.detail.cover_url, // 分享图标
                    success: function () {

                    }
                  })
                // config信息验证后会执行ready方法，所有接口调用都必须在config接口获得结果之后，config是一个客户端的异步操作，所以如果需要在页面加载时就调用相关接口，则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口，则可以直接调用，不需要放在ready函数中。
              });
              wx.error(function(res){

                // config信息验证失败会执行error函数，如签名过期导致验证失败，具体错误信息可以打开config的debug模式查看，也可以在返回的res参数中查看，对于SPA可以在这里更新签名。
              });
            }, function (errorresult) {

            }, "POST", false)

            // wx.ready(function () {   //需在用户可能点击分享按钮前就先调用
            //   alert(that.detail.title + "ready")
            //
            // });
            // wx.ready(function () {   //需在用户可能点击分享按钮前就先调用
            //   wx.updateTimelineShareData({
            //     title: that.detail.title == '' ? '我在妙汇发现了一篇笔记' : that.detail.title, // 分享标题
            //     link: window.location.href, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
            //     imgUrl: that.detail.cover_url, // 分享图标
            //     success: function () {
            //
            //     }
            //   })
            // });
            that.getCommentList();
          }, function (errorresult) {

          }, "GET", true)

        }
      },
      submitComment() {
        var that = this
        var params = {note_id: that.detail.id, content: "这是我的评论！" + new Date().toLocaleTimeString()}
        httputil.request("note/comment", params, function (successresult) {
          utils.toast("评论成功")
        }, function (errorresult) {

        }, "POST", true, "notedetail")
      },
      getCommentList() {
        var that = this
        var params = {note_id: that.id}
        httputil.request("note/comments", params, function (successresult) {
          that.commentlist = successresult.comment_list.comments
        }, function (errorresult) {

        }, "GET", true, "notedetail")
      },
      collect() {
        var that = this
        if (this.app.$getLoginStatus()) {
          if (this.detail.collected == 0) {
            this.detail.collected = 1
            this.detail.collected_total = this.detail.collected_total + 1
          } else {
            this.detail.collected = 0
            this.detail.collected_total = this.detail.collected_total - 1
          }
          // this.detail.collected == 0 ? this.detail.collected = 1 : this.detail.collected = 0
        }
        var params = {id: this.detail.id}
        httputil.request("collect/note", params, function (successresult) {
          that.detail.collected = successresult.collected
        }, function (errorresult) {

        }, "POST", false, "notedetail")
      },
      like() {
        var that = this
        if (this.app.$getLoginStatus()) {
          if (this.detail.liked == 0) {
            this.detail.liked = 1
            this.detail.liked_total = this.detail.liked_total + 1
          } else {
            this.detail.liked = 0
            this.detail.liked_total = this.detail.liked_total - 1
          }
        }
        var params = {id: this.detail.id}
        httputil.request("like/note", params, function (successresult) {
          that.detail.liked = successresult.liked
        }, function (errorresult) {

        }, "POST", false, "notedetail")
      },
      commentlike(item) {
        var that = this
        if (this.app.$getLoginStatus()) {
          if (item.liked == 0) {
            item.liked = 1
            item.liked_total = item.liked_total + 1
          } else {
            item.liked = 0
            item.liked_total = item.liked_total - 1
          }
        }
        var params = {id: item.id}
        httputil.request("like/note-comment", params, function (successresult) {
          item.liked = successresult.liked
        }, function (errorresult) {

        }, "POST", false, "notedetail")
      },
      follow(id) {
        var that = this
        // if (this.app.$getLoginStatus()) {
        //   if (this.detail.user.followed == 0) {
        //     this.detail.user.followed = 1
        //   } else {
        //     this.detail.user.followed = 0
        //   }
        // }
        var params = {id: this.detail.user.id}
        httputil.request("fans/followed", params, function (successresult) {
          that.detail.user.followed = successresult.followed
        }, function (errorresult) {

        }, "POST", false, "notedetail")
      },
      skipToUserpage(id) {
        this.needFetch = false
        this.app.$router.push({name: 'userpage', query: {id: id}})
      },

      skipToDownload() {
        this.needFetch = false
        this.app.$router.push({name: 'downloadpage'})
      }
    },
    help: {
      data() {
        return {
          api: "about/rules",
          detail: {},
          needFetch: true,
        }
      },

      async fetch() {
        if (this.needFetch) {
          var that = this
          this.detail = {}
          if (this.app.$route.query.type == "rules"){
            this.api = "about/rules"
          } else if (this.app.$route.query.type == "statement"){
            this.api = "about/statement"
          }
          var params = {}
          httputil.request(this.api, params, function (successresult) {
            that.detail = successresult
          }, function (errorresult) {

          }, "GET", true)

        }
      },
    },
    login: {
      data() {
        return {
          inputmobile: "",
          inputcode: "",
          countdown: 0,
          getcodestatus: 0,
          isWxMobileBrowser: false,
          redirecturi: "",
          type: "wxwap"
        }
      },
      route: {
        once: true // 当前页面，只加载一次，这样我们就可以做上拉加载了
      },
      checkmobilestatus() {
        if (this.inputmobile.length > 11) {
          utils.toast("手机号不能超过11位哦")
          this.inputmobile = this.inputmobile.slice(0, 11)
          if (this.countdown == 0) {
            this.getcodestatus = 1;
          }
        } else if (this.inputmobile.length == 11) {
          if (this.countdown == 0) {
            this.getcodestatus = 1;
          }
        } else {
          if (this.countdown == 0) {
            this.getcodestatus = 0;
          }
        }
      },
      deleteMobile() {
        this.inputmobile = ""
        this.checkmobilestatus()
      },
      getcode() {
        var that = this
        httputil.request("send/sms", {mobile: that.inputmobile}, function (successresult) {
          that.getcodestatus = 2;
          that.countdowntime();
        }, function (errorresult) {

        }, "POST", true)
      },
      sendLogin() {
        var that = this
        httputil.request("login/mobile", {mobile: that.inputmobile, code: that.inputcode}, function (successresult) {
          localStorage.setItem("Accept-Token", successresult.token)
          that.app.$BackRoute(-1)
        }, function (errorresult) {

        }, "POST", true)
      },
      countdowntime() {
        var that = this;
        that.countdown = 60
        var timer = setInterval(function () {
          that.countdown = that.countdown - 1;
          if (that.countdown == 0) {
            that.getcodestatus = 3;
            clearInterval(timer);
          }
        }, 1000);
      },
      sendWx() {
        window.location.href = this.redirecturi;
      },
      wxlogin(code) {
        var that = this
        var params = {oauth: this.type, code: code}
        httputil.request("login/oauth", params, function (successresult) {
          localStorage.setItem("Accept-Token", successresult.token)
          that.app.$BackRoute(localStorage.getItem("loginhistorycount") - window.history.length - 1)
        }, function () {

        }, "POST", true)
      },
      async fetch() {
        var that = this
        this.isWxMobileBrowser = this.app.$isWxMobileBrowser()
        if (window.location.search.lastIndexOf('code=') !== -1) {
          this.wxlogin(window.location.search.substring(window.location.search.lastIndexOf('code=') + 5, window.location.search.lastIndexOf('&')))
        } else {
          localStorage.setItem("loginhistorycount", window.history.length)
          httputil.request("login/oauth", {redirect_uri: window.location.href}, function (successresult) {
            that.redirecturi = successresult.oauth_list.wxwap.redirect_uri
            that.type = successresult.oauth_list.wxwap.type
          }, function () {

          }, "GET", false)
        }
      }
    },

    test: {
      data() {
        return {
          message: "",
        }
      },
      route: {
        once: true
      },
      fetch() {

      }
    }
  }
})
